Debian Codegraph @

src/java.c

raw symbols SCIP
1 /* Conversion of files between different charsets and surfaces.
2 Copyright © 2008-2019 Free Software Foundation, Inc.
3 Contributed by François Pinard <[email protected]>, 2008.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public License
7 as published by the Free Software Foundation; either version 3 of the
8 License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be
11 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the Recode Library; see the file `COPYING.LIB'.
17 If not, see <https://www.gnu.org/licenses/>.
18 */
19
20 #include "config.h"
21 #include "common.h"
22 #include "decsteps.h"
23
24 static bool
25 transform_java_utf16 (RECODE_SUBTASK subtask)
26 {
27 int character = recode_get_byte (subtask);
28
29 while (character != EOF)
30 if (character == '\\')
31 {
32 char buffer[6];
33 char *cursor = buffer;
34 unsigned value = 0;
35 bool canonical = true;
36
37 *cursor++ = character;
38 character = recode_get_byte (subtask);
39 if (character == 'u' || character == 'U')
40 {
41 if (character == 'U')
42 canonical = false;
43 *cursor++ = character;
44 character = recode_get_byte (subtask);
45 while (cursor < buffer + 6)
46 {
47 if (character >= '0' && character <= '9')
48 value = (value << 4) | (character - '0');
49 else if (character >= 'A' && character <= 'F')
50 {
51 value = (value << 4) | (character - 'A' + 10);
52 canonical = false;
53 }
54 else if (character >= 'a' && character <= 'f')
55 value = (value << 4) | (character - 'a' + 10);
56 else
57 break;
58 *cursor++ = character;
59 character = recode_get_byte (subtask);
60 }
61 if (cursor == buffer + 6)
62 {
63 if (!canonical)
64 RETURN_IF_NOGO (RECODE_NOT_CANONICAL, subtask);
65 recode_put_ucs2 (value, subtask);
66 continue;
67 }
68 }
69 *cursor = '\0';
70 for (cursor = buffer; *cursor; cursor++)
71 recode_put_ucs2 (*cursor, subtask);
72 }
73 else
74 {
75 recode_put_ucs2 (character, subtask);
76 character = recode_get_byte (subtask);
77 }
78
79 SUBTASK_RETURN (subtask);
80 }
81
82 static bool
83 transform_utf16_java (RECODE_SUBTASK subtask)
84 {
85 unsigned value;
86
87 while (recode_get_ucs2 (&value, subtask))
88 if (value < 128)
89 recode_put_byte (value, subtask);
90 else
91 {
92 char buffer[11];
93 char *cursor;
94
95 sprintf (buffer, "\\u%04x", value);
96 for (cursor = buffer; *cursor; cursor++)
97 recode_put_byte (*cursor, subtask);
98 }
99
100 SUBTASK_RETURN (subtask);
101 }
102
103 bool
104 module_java (RECODE_OUTER outer)
105 {
106 return
107 recode_declare_single (outer, "UTF-16", "Java",
108 outer->quality_ucs2_to_variable,
109 NULL, transform_utf16_java)
110 && recode_declare_single (outer, "Java", "UTF-16",
111 outer->quality_variable_to_ucs2,
112 NULL, transform_java_utf16);
113 }
114
115 void
116 delmodule_java (_GL_UNUSED RECODE_OUTER outer)
117 {
118 }