1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3 *
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
8 *
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
13 *
14 * The Initial Developer of the Original Code is Fireinput Inc.
15 *
16 * Portions created by the Initial Developer are Copyright (C) 2007
17 * the Initial Developer. All Rights Reserved.
18 *
19 * Contributor(s):
20 * Olly Ja <ollyja@gmail.com>
21 *
22 * Alternatively, the contents of this file may be used under the terms of
23 * either the GNU General Public License Version 2 or later (the "GPL"), or
24 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
25 * in which case the provisions of the GPL or the LGPL are applicable instead
26 * of those above. If you wish to allow use of your version of this file only
27 * under the terms of either the GPL or the LGPL, and not to allow others to
28 * use your version of this file under the terms of the MPL, indicate your
29 * decision by deleting the provisions above and replace them with the notice
30 * and other provisions required by the GPL or the LGPL. If you do not delete
31 * the provisions above, a recipient may use your version of this file under
32 * the terms of any one of the MPL, the GPL or the LGPL.
33 *
34 * ***** END LICENSE BLOCK *****
35 */
36
37 const HALF_FULL_TABLE = [
38 { half: '0020', full: '3000', next: 1 },
39 { half: '0021', full: 'FF01', next: 94 },
40 { half: '00A1', full: 'FFE0', next: 2 },
41 { half: '00A5', full: 'FFE5', next: 1 },
42 { half: '00A6', full: 'FFE4', next: 1 },
43 { half: '00AC', full: 'FFE2', next: 1 },
44 { half: '00AF', full: 'FFE3', next: 1 },
45 { half: '20A9', full: 'FFE6', next: 1 },
46 { half: 'FF61', full: '3002', next: 1 },
47 { half: 'FF62', full: '300C', next: 2 },
48 { half: 'FF64', full: '3001', next: 1 },
49 { half: 'FF65', full: '30FB', next: 1 },
50 { half: 'FF66', full: '30F2', next: 1 },
51 { half: 'FF67', full: '30A1', next: 1 },
52 { half: 'FF68', full: '30A3', next: 1 },
53 { half: 'FF69', full: '30A5', next: 1 },
54 { half: 'FF6A', full: '30A7', next: 1 },
55 { half: 'FF6B', full: '30A9', next: 1 },
56 { half: 'FF6C', full: '30E3', next: 1 },
57 { half: 'FF6D', full: '30E5', next: 1 },
58 { half: 'FF6E', full: '30E7', next: 1 },
59 { half: 'FF6F', full: '30C3', next: 1 },
60 { half: 'FF70', full: '30FC', next: 1 },
61 { half: 'FF71', full: '30A2', next: 1 },
62 { half: 'FF72', full: '30A4', next: 1 },
63 { half: 'FF73', full: '30A6', next: 1 },
64 { half: 'FF74', full: '30A8', next: 1 },
65 { half: 'FF75', full: '30AA', next: 2 },
66 { half: 'FF77', full: '30AD', next: 1 },
67 { half: 'FF78', full: '30AF', next: 1 },
68 { half: 'FF79', full: '30B1', next: 1 },
69 { half: 'FF7A', full: '30B3', next: 1 },
70 { half: 'FF7B', full: '30B5', next: 1 },
71 { half: 'FF7C', full: '30B7', next: 1 },
72 { half: 'FF7D', full: '30B9', next: 1 },
73 { half: 'FF7E', full: '30BB', next: 1 },
74 { half: 'FF7F', full: '30BD', next: 1 },
75 { half: 'FF80', full: '30BF', next: 1 },
76 { half: 'FF81', full: '30C1', next: 1 },
77 { half: 'FF82', full: '30C4', next: 1 },
78 { half: 'FF83', full: '30C6', next: 1 },
79 { half: 'FF84', full: '30C8', next: 1 },
80 { half: 'FF85', full: '30CA', next: 6 },
81 { half: 'FF8B', full: '30D2', next: 1 },
82 { half: 'FF8C', full: '30D5', next: 1 },
83 { half: 'FF8D', full: '30D8', next: 1 },
84 { half: 'FF8E', full: '30DB', next: 1 },
85 { half: 'FF8F', full: '30DE', next: 5 },
86 { half: 'FF94', full: '30E4', next: 1 },
87 { half: 'FF95', full: '30E6', next: 1 },
88 { half: 'FF96', full: '30E8', next: 6 },
89 { half: 'FF9C', full: '30EF', next: 1 },
90 { half: 'FF9D', full: '30F3', next: 1 },
91 { half: 'FFA0', full: '3164', next: 1 },
92 { half: 'FFA1', full: '3131', next: 30},
93 { half: 'FFC2', full: '314F', next: 6 },
94 { half: 'FFCA', full: '3155', next: 6 },
95 { half: 'FFD2', full: '315B', next: 9 },
96 { half: 'FFE9', full: '2190', next: 4 },
97 { half: 'FFED', full: '25A0', next: 1 },
98 { half: 'FFEE', full: '25CB', next: 1 }
99 ];
100
101 var FullLetterConverter = function() {};
102
103 FullLetterConverter.prototype =
104 {
105 double_quot_stat: 0,
106 single_quot_stat: 0,
107 double_right_arrow: 0,
108 double_left_arrow: 0,
109 single_right_arrow: 0,
110 single_left_arrow: 0,
111
112
113 toFullLetter: function(key)
114 {
115 switch(key)
116 {
117 case ',':
118 return "\uFF0C";
119 case '.':
120 return "\u3002";
121 case '\\':
122 return "\u3001";
123 case ';':
124 return "\uFF1B";
125 case '[':
126 return "\uFF3B";
127 case ']':
128 return "\uFF3D";
129 case '^':
130 return ["\u2026", "\u2026"];
131 case '"':
132 if(this.double_quot_state)
133 {
134 this.double_quot_state = 0;
135 return "\u201D";
136 }
137 else
138 {
139 this.double_quot_state = 1;
140 return "\u201C";
141 }
142 case '\'':
143 if(this.single_quot_state)
144 {
145 this.single_quot_state = 0;
146 return "\u2019";
147 }
148 else
149 {
150 this.single_quot_state = 1;
151 return "\u2018";
152 }
153 case '<':
154 if(!this.double_left_arrow)
155 {
156 this.double_left_arrow = 1;
157 this.double_right_arrow = 0;
158 this.single_left_arrow = 0;
159 return "\u300A";
160 }
161 else
162 {
163 this.single_left_arrow++;
164 return "\u3008";
165 }
166
167 case '>':
168 if(this.single_right_arrow < this.single_left_arrow)
169 {
170 this.single_right_arrow++;
171 return "\u3009";
172 }
173 else
174 {
175 this.double_right_arrow = 1;
176 this.double_left_arrow = 0;
177 this.single_right_arrow = 0;
178 this.single_left_arrow = 0;
179 return "\u300B";
180 }
181
182 case '$':
183 return "\uFFE5";
184
185 case '_':
186 return ["\u2014", "\u2014"];
187
188 case '(':
189 return "\uFF08";
190 case ')':
191 return "\uFF09";
192
193 case '{':
194 return "\uFF5B";
195 case '}':
196 return "\uFF5D";
197
198 default:
199 return this.convertToFullLetter(key);
200 }
201 },
202
203 convertToFullLetter: function(key)
204 {
205 var charCode = key.charCodeAt(0);
206 for (var i=HALF_FULL_TABLE.length-1; i>=0; i--)
207 {
208 var halfCode = parseInt(HALF_FULL_TABLE[i].half, 16);
209 var fullCode = parseInt(HALF_FULL_TABLE[i].full, 16);
210 if(charCode >= halfCode &&
211 charCode < (halfCode + HALF_FULL_TABLE[i].next))
212 return String.fromCharCode(fullCode + charCode - halfCode);
213 }
214
215 return key;
216 },
217
218 convertToHalfLetter: function(key)
219 {
220 var charCode = key.charCodeAt(0);
221 for (var i=HALF_FULL_TABLE.length-1; i>=0; i--)
222 {
223 var halfCode = parseInt(HALF_FULL_TABLE[i].half, 16);
224 var fullCode = parseInt(HALF_FULL_TABLE[i].full, 16);
225 if(charCode >= fullCode &&
226 charCode < (fullCode + HALF_FULL_TABLE[i].next))
227 return String.fromCharCode(halfCode + charCode - fullCode);
228 }
229
230 return key;
231 }
232
233 };
syntax highlighted by Code2HTML, v. 0.9.1