Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include <utility>
22 : #include <comphelper/string.hxx>
23 : #include <i18nutil/oneToOneMapping.hxx>
24 : #define TRANSLITERATION_IterationMark_ja_JP
25 : #include <transliteration_Ignore.hxx>
26 :
27 : using namespace com::sun::star::uno;
28 : using namespace com::sun::star::lang;
29 :
30 :
31 : namespace com { namespace sun { namespace star { namespace i18n {
32 :
33 : OneToOneMappingTable_t ignoreIterationMark_ja_JP_mappingTable[] = {
34 : { 0x3046, 0x3094 }, // HIRAGANA LETTER U --> HIRAGANA LETTER VU
35 : { 0x304B, 0x304C }, // HIRAGANA LETTER KA --> HIRAGANA LETTER GA
36 : { 0x304D, 0x304E }, // HIRAGANA LETTER KI --> HIRAGANA LETTER GI
37 : { 0x304F, 0x3050 }, // HIRAGANA LETTER KU --> HIRAGANA LETTER GU
38 : { 0x3051, 0x3052 }, // HIRAGANA LETTER KE --> HIRAGANA LETTER GE
39 : { 0x3053, 0x3054 }, // HIRAGANA LETTER KO --> HIRAGANA LETTER GO
40 : { 0x3055, 0x3056 }, // HIRAGANA LETTER SA --> HIRAGANA LETTER ZA
41 : { 0x3057, 0x3058 }, // HIRAGANA LETTER SI --> HIRAGANA LETTER ZI
42 : { 0x3059, 0x305A }, // HIRAGANA LETTER SU --> HIRAGANA LETTER ZU
43 : { 0x305B, 0x305C }, // HIRAGANA LETTER SE --> HIRAGANA LETTER ZE
44 : { 0x305D, 0x305E }, // HIRAGANA LETTER SO --> HIRAGANA LETTER ZO
45 : { 0x305F, 0x3060 }, // HIRAGANA LETTER TA --> HIRAGANA LETTER DA
46 : { 0x3061, 0x3062 }, // HIRAGANA LETTER TI --> HIRAGANA LETTER DI
47 : { 0x3064, 0x3065 }, // HIRAGANA LETTER TU --> HIRAGANA LETTER DU
48 : { 0x3066, 0x3067 }, // HIRAGANA LETTER TE --> HIRAGANA LETTER DE
49 : { 0x3068, 0x3069 }, // HIRAGANA LETTER TO --> HIRAGANA LETTER DO
50 : { 0x306F, 0x3070 }, // HIRAGANA LETTER HA --> HIRAGANA LETTER BA
51 : { 0x3072, 0x3073 }, // HIRAGANA LETTER HI --> HIRAGANA LETTER BI
52 : { 0x3075, 0x3076 }, // HIRAGANA LETTER HU --> HIRAGANA LETTER BU
53 : { 0x3078, 0x3079 }, // HIRAGANA LETTER HE --> HIRAGANA LETTER BE
54 : { 0x307B, 0x307C }, // HIRAGANA LETTER HO --> HIRAGANA LETTER BO
55 : { 0x309D, 0x309E }, // HIRAGANA ITERATION MARK --> HIRAGANA VOICED ITERATION MARK
56 : { 0x30A6, 0x30F4 }, // KATAKANA LETTER U --> KATAKANA LETTER VU
57 : { 0x30AB, 0x30AC }, // KATAKANA LETTER KA --> KATAKANA LETTER GA
58 : { 0x30AD, 0x30AE }, // KATAKANA LETTER KI --> KATAKANA LETTER GI
59 : { 0x30AF, 0x30B0 }, // KATAKANA LETTER KU --> KATAKANA LETTER GU
60 : { 0x30B1, 0x30B2 }, // KATAKANA LETTER KE --> KATAKANA LETTER GE
61 : { 0x30B3, 0x30B4 }, // KATAKANA LETTER KO --> KATAKANA LETTER GO
62 : { 0x30B5, 0x30B6 }, // KATAKANA LETTER SA --> KATAKANA LETTER ZA
63 : { 0x30B7, 0x30B8 }, // KATAKANA LETTER SI --> KATAKANA LETTER ZI
64 : { 0x30B9, 0x30BA }, // KATAKANA LETTER SU --> KATAKANA LETTER ZU
65 : { 0x30BB, 0x30BC }, // KATAKANA LETTER SE --> KATAKANA LETTER ZE
66 : { 0x30BD, 0x30BE }, // KATAKANA LETTER SO --> KATAKANA LETTER ZO
67 : { 0x30BF, 0x30C0 }, // KATAKANA LETTER TA --> KATAKANA LETTER DA
68 : { 0x30C1, 0x30C2 }, // KATAKANA LETTER TI --> KATAKANA LETTER DI
69 : { 0x30C4, 0x30C5 }, // KATAKANA LETTER TU --> KATAKANA LETTER DU
70 : { 0x30C6, 0x30C7 }, // KATAKANA LETTER TE --> KATAKANA LETTER DE
71 : { 0x30C8, 0x30C9 }, // KATAKANA LETTER TO --> KATAKANA LETTER DO
72 : { 0x30CF, 0x30D0 }, // KATAKANA LETTER HA --> KATAKANA LETTER BA
73 : { 0x30D2, 0x30D3 }, // KATAKANA LETTER HI --> KATAKANA LETTER BI
74 : { 0x30D5, 0x30D6 }, // KATAKANA LETTER HU --> KATAKANA LETTER BU
75 : { 0x30D8, 0x30D9 }, // KATAKANA LETTER HE --> KATAKANA LETTER BE
76 : { 0x30DB, 0x30DC }, // KATAKANA LETTER HO --> KATAKANA LETTER BO
77 : { 0x30EF, 0x30F7 }, // KATAKANA LETTER WA --> KATAKANA LETTER VA
78 : { 0x30F0, 0x30F8 }, // KATAKANA LETTER WI --> KATAKANA LETTER VI
79 : { 0x30F1, 0x30F9 }, // KATAKANA LETTER WE --> KATAKANA LETTER VE
80 : { 0x30F2, 0x30FA }, // KATAKANA LETTER WO --> KATAKANA LETTER VO
81 : { 0x30FD, 0x30FE } // KATAKANA ITERATION MARK --> KATAKANA VOICED ITERATION MARK
82 : };
83 :
84 :
85 : OUString SAL_CALL
86 0 : ignoreIterationMark_ja_JP::folding( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount, Sequence< sal_Int32 >& offset )
87 : throw(RuntimeException, std::exception)
88 : {
89 0 : oneToOneMapping aTable(ignoreIterationMark_ja_JP_mappingTable, sizeof(ignoreIterationMark_ja_JP_mappingTable));
90 :
91 : // Create a string buffer which can hold nCount + 1 characters.
92 : // The reference count is 1 now.
93 0 : rtl_uString * newStr = rtl_uString_alloc(nCount);
94 0 : sal_Unicode * dst = newStr->buffer;
95 0 : const sal_Unicode * src = inStr.getStr() + startPos;
96 :
97 0 : sal_Int32 * p = 0;
98 0 : sal_Int32 position = 0;
99 0 : if (useOffset) {
100 : // Allocate nCount length to offset argument.
101 0 : offset.realloc( nCount );
102 0 : p = offset.getArray();
103 0 : position = startPos;
104 : }
105 :
106 :
107 0 : sal_Unicode previousChar = *src ++;
108 : sal_Unicode currentChar;
109 :
110 : // Conversion
111 0 : while (-- nCount > 0) {
112 0 : currentChar = *src ++;
113 :
114 0 : switch ( currentChar ) {
115 : case 0x30fd: // KATAKANA ITERATION MARK
116 : case 0x309d: // HIRAGANA ITERATION MARK
117 : case 0x3005: // IDEOGRAPHIC ITERATION MARK
118 0 : currentChar = previousChar;
119 0 : break;
120 : case 0x30fe: // KATAKANA VOICED ITERATION MARK
121 : case 0x309e: // HIRAGANA VOICED ITERATION MARK
122 0 : currentChar = aTable[ previousChar ];
123 0 : break;
124 : }
125 0 : if (useOffset)
126 0 : *p ++ = position ++;
127 0 : *dst ++ = previousChar;
128 0 : previousChar = currentChar;
129 : }
130 :
131 0 : if (nCount == 0) {
132 0 : if (useOffset)
133 0 : *p = position;
134 0 : *dst ++ = previousChar;
135 : }
136 :
137 0 : *dst = (sal_Unicode) 0;
138 :
139 0 : newStr->length = sal_Int32(dst - newStr->buffer);
140 0 : if (useOffset)
141 0 : offset.realloc(newStr->length);
142 0 : return OUString(newStr, SAL_NO_ACQUIRE); // take ownership
143 :
144 : }
145 :
146 : } } } }
147 :
148 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|