Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libjava / gnu / gcj / convert / Input_JavaSrc.java
blob12b8b695bfad90d0f8445c35269838065a28dbf5
1 /* Copyright (C) 1999 Free Software Foundation
3 This file is part of libgcj.
5 This software is copyrighted work licensed under the terms of the
6 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
7 details. */
9 package gnu.gcj.convert;
11 /**
12 * Convert Ascii with \ u XXXX-escapes to Unicode.
13 * @author Per Bothner <bothner@cygnus.com>
14 * @date April 1999.
17 public class Input_JavaSrc extends BytesToUnicode
19 public String getName() { return "JavaSrc"; }
21 // 0: normal
22 // 1: seen '\\'
23 // 2: seen '\\' and 'u'
24 // 3: seen '\\' and need to emit value.
25 // 4, 5, 6, 7: seen '\\u', 'u' and (state-3) hex digits.
26 int state = 0;
28 int value;
30 public int read (char[] outbuffer, int outpos, int count)
32 int origpos = outpos;
33 for (;;)
35 if (inpos >= inlength)
36 break;
37 if (outpos - origpos >= count)
38 break;
39 char b = (char) (inbuffer[inpos++] & 0xFF);
40 switch (state)
42 case 0:
43 if (b == '\\')
45 state = 1;
46 continue;
48 break;
49 case 1:
50 if (b == 'u')
52 state = 2;
53 continue;
55 if (b != '\\')
57 value = b;
58 b = '\\';
59 state = 3;
61 break;
62 case 3:
63 b = (char) value;
64 break;
65 default: // case 4: case 5: case 6: case 7:
66 int digit = Character.digit(b, 16);
67 if (digit < 0)
69 b = '\uFFFD';
70 state = 0;
72 else
74 value = value * 16 + digit;
75 if (state < 7)
77 state++;
78 continue;
80 b = (char) value;
82 state = 0;
84 outbuffer[outpos++] = b;
86 return outpos - origpos;