1 /* Copyright (C) 2000 Free Software Foundation 2 3 This file is part of libgcj. 4 5 This software is copyrighted work licensed under the terms of the 6 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for 7 details. */ 8 9 package gnu.gcj.convert; 10 11 /** 12 * Convert Unicode ASCII 13 * Unrecognized characters are printed as `?'. 14 * @date October 2000 15 */ 16 17 public class Output_ASCII extends UnicodeToBytes 18 { getName()19 public String getName() { return "ASCII"; } 20 21 /** 22 * @return number of chars converted. */ write(char[] inbuffer, int inpos, int inlength)23 public int write (char[] inbuffer, int inpos, int inlength) 24 { 25 int count = this.count; 26 byte[] buf = this.buf; 27 int avail = buf.length - count; 28 if (inlength > avail) 29 inlength = avail; 30 for (int i = inlength; --i >= 0; ) 31 { 32 char c = inbuffer[inpos++]; 33 buf[count++] = (byte) ((c > 0x7f) ? '?' : c); 34 } 35 this.count = count; 36 return inlength; 37 } 38 write(String str, int inpos, int inlength, char[] work)39 public int write (String str, int inpos, int inlength, char[] work) 40 { 41 int count = this.count; 42 byte[] buf = this.buf; 43 int avail = buf.length - count; 44 if (inlength > avail) 45 inlength = avail; 46 for (int i = inlength; --i >= 0; ) 47 { 48 char c = str.charAt(inpos++); 49 buf[count++] = (byte) ((c > 0x7f) ? '?' : c); 50 } 51 this.count = count; 52 return inlength; 53 } 54 } 55