001: package org.apache.lucene.analysis.ru;
002:
003: /**
004:
005: * Copyright 2004 The Apache Software Foundation
006:
007: *
008:
009: * Licensed under the Apache License, Version 2.0 (the "License");
010:
011: * you may not use this file except in compliance with the License.
012:
013: * You may obtain a copy of the License at
014:
015: *
016:
017: * http://www.apache.org/licenses/LICENSE-2.0
018:
019: *
020:
021: * Unless required by applicable law or agreed to in writing, software
022:
023: * distributed under the License is distributed on an "AS IS" BASIS,
024:
025: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
026:
027: * See the License for the specific language governing permissions and
028:
029: * limitations under the License.
030:
031: */
032:
033: /**
034:
035: * RussianCharsets class contains encodings schemes (charsets) and toLowerCase() method implementation
036:
037: * for russian characters in Unicode, KOI8 and CP1252.
038:
039: * Each encoding scheme contains lowercase (positions 0-31) and uppercase (position 32-63) characters.
040:
041: * One should be able to add other encoding schemes (like ISO-8859-5 or customized) by adding a new charset
042:
043: * and adding logic to toLowerCase() method for that charset.
044:
045: *
046:
047: * @author Boris Okner, b.okner@rogers.com
048:
049: * @version $Id: RussianCharsets.java,v 1.1 2005/06/02 01:35:59 jfendler Exp $
050:
051: */
052:
053: public class RussianCharsets
054:
055: {
056:
057: // Unicode Russian charset (lowercase letters only)
058:
059: public static char[] UnicodeRussian = {
060:
061: '\u0430',
062:
063: '\u0431',
064:
065: '\u0432',
066:
067: '\u0433',
068:
069: '\u0434',
070:
071: '\u0435',
072:
073: '\u0436',
074:
075: '\u0437',
076:
077: '\u0438',
078:
079: '\u0439',
080:
081: '\u043A',
082:
083: '\u043B',
084:
085: '\u043C',
086:
087: '\u043D',
088:
089: '\u043E',
090:
091: '\u043F',
092:
093: '\u0440',
094:
095: '\u0441',
096:
097: '\u0442',
098:
099: '\u0443',
100:
101: '\u0444',
102:
103: '\u0445',
104:
105: '\u0446',
106:
107: '\u0447',
108:
109: '\u0448',
110:
111: '\u0449',
112:
113: '\u044A',
114:
115: '\u044B',
116:
117: '\u044C',
118:
119: '\u044D',
120:
121: '\u044E',
122:
123: '\u044F',
124:
125: // upper case
126:
127: '\u0410',
128:
129: '\u0411',
130:
131: '\u0412',
132:
133: '\u0413',
134:
135: '\u0414',
136:
137: '\u0415',
138:
139: '\u0416',
140:
141: '\u0417',
142:
143: '\u0418',
144:
145: '\u0419',
146:
147: '\u041A',
148:
149: '\u041B',
150:
151: '\u041C',
152:
153: '\u041D',
154:
155: '\u041E',
156:
157: '\u041F',
158:
159: '\u0420',
160:
161: '\u0421',
162:
163: '\u0422',
164:
165: '\u0423',
166:
167: '\u0424',
168:
169: '\u0425',
170:
171: '\u0426',
172:
173: '\u0427',
174:
175: '\u0428',
176:
177: '\u0429',
178:
179: '\u042A',
180:
181: '\u042B',
182:
183: '\u042C',
184:
185: '\u042D',
186:
187: '\u042E',
188:
189: '\u042F'
190:
191: };
192:
193: // KOI8 charset
194:
195: public static char[] KOI8 = {
196:
197: 0xc1,
198:
199: 0xc2,
200:
201: 0xd7,
202:
203: 0xc7,
204:
205: 0xc4,
206:
207: 0xc5,
208:
209: 0xd6,
210:
211: 0xda,
212:
213: 0xc9,
214:
215: 0xca,
216:
217: 0xcb,
218:
219: 0xcc,
220:
221: 0xcd,
222:
223: 0xce,
224:
225: 0xcf,
226:
227: 0xd0,
228:
229: 0xd2,
230:
231: 0xd3,
232:
233: 0xd4,
234:
235: 0xd5,
236:
237: 0xc6,
238:
239: 0xc8,
240:
241: 0xc3,
242:
243: 0xde,
244:
245: 0xdb,
246:
247: 0xdd,
248:
249: 0xdf,
250:
251: 0xd9,
252:
253: 0xd8,
254:
255: 0xdc,
256:
257: 0xc0,
258:
259: 0xd1,
260:
261: // upper case
262:
263: 0xe1,
264:
265: 0xe2,
266:
267: 0xf7,
268:
269: 0xe7,
270:
271: 0xe4,
272:
273: 0xe5,
274:
275: 0xf6,
276:
277: 0xfa,
278:
279: 0xe9,
280:
281: 0xea,
282:
283: 0xeb,
284:
285: 0xec,
286:
287: 0xed,
288:
289: 0xee,
290:
291: 0xef,
292:
293: 0xf0,
294:
295: 0xf2,
296:
297: 0xf3,
298:
299: 0xf4,
300:
301: 0xf5,
302:
303: 0xe6,
304:
305: 0xe8,
306:
307: 0xe3,
308:
309: 0xfe,
310:
311: 0xfb,
312:
313: 0xfd,
314:
315: 0xff,
316:
317: 0xf9,
318:
319: 0xf8,
320:
321: 0xfc,
322:
323: 0xe0,
324:
325: 0xf1
326:
327: };
328:
329: // CP1251 eharset
330:
331: public static char[] CP1251 = {
332:
333: 0xE0,
334:
335: 0xE1,
336:
337: 0xE2,
338:
339: 0xE3,
340:
341: 0xE4,
342:
343: 0xE5,
344:
345: 0xE6,
346:
347: 0xE7,
348:
349: 0xE8,
350:
351: 0xE9,
352:
353: 0xEA,
354:
355: 0xEB,
356:
357: 0xEC,
358:
359: 0xED,
360:
361: 0xEE,
362:
363: 0xEF,
364:
365: 0xF0,
366:
367: 0xF1,
368:
369: 0xF2,
370:
371: 0xF3,
372:
373: 0xF4,
374:
375: 0xF5,
376:
377: 0xF6,
378:
379: 0xF7,
380:
381: 0xF8,
382:
383: 0xF9,
384:
385: 0xFA,
386:
387: 0xFB,
388:
389: 0xFC,
390:
391: 0xFD,
392:
393: 0xFE,
394:
395: 0xFF,
396:
397: // upper case
398:
399: 0xC0,
400:
401: 0xC1,
402:
403: 0xC2,
404:
405: 0xC3,
406:
407: 0xC4,
408:
409: 0xC5,
410:
411: 0xC6,
412:
413: 0xC7,
414:
415: 0xC8,
416:
417: 0xC9,
418:
419: 0xCA,
420:
421: 0xCB,
422:
423: 0xCC,
424:
425: 0xCD,
426:
427: 0xCE,
428:
429: 0xCF,
430:
431: 0xD0,
432:
433: 0xD1,
434:
435: 0xD2,
436:
437: 0xD3,
438:
439: 0xD4,
440:
441: 0xD5,
442:
443: 0xD6,
444:
445: 0xD7,
446:
447: 0xD8,
448:
449: 0xD9,
450:
451: 0xDA,
452:
453: 0xDB,
454:
455: 0xDC,
456:
457: 0xDD,
458:
459: 0xDE,
460:
461: 0xDF
462:
463: };
464:
465: public static char toLowerCase(char letter, char[] charset)
466:
467: {
468:
469: if (charset == UnicodeRussian)
470:
471: {
472:
473: if (letter >= '\u0430' && letter <= '\u044F')
474:
475: {
476:
477: return letter;
478:
479: }
480:
481: if (letter >= '\u0410' && letter <= '\u042F')
482:
483: {
484:
485: return (char) (letter + 32);
486:
487: }
488:
489: }
490:
491: if (charset == KOI8)
492:
493: {
494:
495: if (letter >= 0xe0 && letter <= 0xff)
496:
497: {
498:
499: return (char) (letter - 32);
500:
501: }
502:
503: if (letter >= 0xc0 && letter <= 0xdf)
504:
505: {
506:
507: return letter;
508:
509: }
510:
511: }
512:
513: if (charset == CP1251)
514:
515: {
516:
517: if (letter >= 0xC0 && letter <= 0xDF)
518:
519: {
520:
521: return (char) (letter + 32);
522:
523: }
524:
525: if (letter >= 0xE0 && letter <= 0xFF)
526:
527: {
528:
529: return letter;
530:
531: }
532:
533: }
534:
535: return Character.toLowerCase(letter);
536:
537: }
538:
539: }
|