| 1 | /* |
| 2 | * $Id: JniMangleFilterWriter.java,v 1.3 2004/05/25 21:04:38 hastings Exp $ |
| 3 | * |
| 4 | * (c) Copyright, Moebius Solutions, Inc., 2004 |
| 5 | * |
| 6 | * All Rights Reserved |
| 7 | * |
| 8 | * This material may be reproduced by or for the U. S. Government |
| 9 | * pursuant to the copyright license under the clause at |
| 10 | * DFARS 252.227-7014 (OCT 2001). |
| 11 | */ |
| 12 | |
| 13 | package com.moesol.generator.core; |
| 14 | |
| 15 | import java.io.*; |
| 16 | |
| 17 | import com.moesol.generator.printer.JniMangledTypePrinter; |
| 18 | |
| 19 | /** |
| 20 | * Filters the outgoing characters so that they can appear as C |
| 21 | * identifiers, per the JNI specification. |
| 22 | */ |
| 23 | public class JniMangleFilterWriter extends FilterWriter { |
| 24 | public JniMangleFilterWriter(Writer out) { |
| 25 | super(out); |
| 26 | } |
| 27 | public void write(char[] cbuf, int off, int len) throws IOException { |
| 28 | int end = off + len; |
| 29 | for (int i = off; i < end; i++) { |
| 30 | write(cbuf[i]); |
| 31 | } |
| 32 | } |
| 33 | public void write(String str, int off, int len) throws IOException { |
| 34 | int end = off + len; |
| 35 | for (int i = off; i < end; i++) { |
| 36 | write(str.charAt(i)); |
| 37 | } |
| 38 | } |
| 39 | public void write(int c) throws IOException { |
| 40 | JniMangledTypePrinter.mangle(c, out); |
| 41 | } |
| 42 | } |