xref: /trunk/main/i18npool/source/transliteration/ignoreIandEfollowedByYa_ja_JP.cxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_i18npool.hxx"
26 
27 // prevent internal compiler error with MSVC6SP3
28 #include <utility>
29 
30 #include <i18nutil/oneToOneMapping.hxx>
31 #define TRANSLITERATION_IandEfollowedByYa_ja_JP
32 #include <transliteration_Ignore.hxx>
33 
34 using namespace com::sun::star::uno;
35 using namespace com::sun::star::lang;
36 using namespace rtl;
37 
38 namespace com { namespace sun { namespace star { namespace i18n {
39 
40 OneToOneMappingTable_t IandE[] = {
41     MAKE_PAIR( 0x30A3, 0x0000 ),  // KATAKANA LETTER SMALL I
42     MAKE_PAIR( 0x30A4, 0x0000 ),  // KATAKANA LETTER I
43     MAKE_PAIR( 0x30A7, 0x0000 ),  // KATAKANA LETTER SMALL E
44     MAKE_PAIR( 0x30A8, 0x0000 ),  // KATAKANA LETTER E
45     MAKE_PAIR( 0x30AD, 0x0000 ),  // KATAKANA LETTER KI
46     MAKE_PAIR( 0x30AE, 0x0000 ),  // KATAKANA LETTER GI
47     MAKE_PAIR( 0x30B1, 0x0000 ),  // KATAKANA LETTER KE
48     MAKE_PAIR( 0x30B2, 0x0000 ),  // KATAKANA LETTER GE
49     MAKE_PAIR( 0x30B7, 0x0000 ),  // KATAKANA LETTER SI
50     MAKE_PAIR( 0x30B8, 0x0000 ),  // KATAKANA LETTER ZI
51     MAKE_PAIR( 0x30BB, 0x0000 ),  // KATAKANA LETTER SE
52     MAKE_PAIR( 0x30BC, 0x0000 ),  // KATAKANA LETTER ZE
53     MAKE_PAIR( 0x30C1, 0x0000 ),  // KATAKANA LETTER TI
54     MAKE_PAIR( 0x30C2, 0x0000 ),  // KATAKANA LETTER DI
55     MAKE_PAIR( 0x30C6, 0x0000 ),  // KATAKANA LETTER TE
56     MAKE_PAIR( 0x30C7, 0x0000 ),  // KATAKANA LETTER DE
57     MAKE_PAIR( 0x30CB, 0x0000 ),  // KATAKANA LETTER NI
58     MAKE_PAIR( 0x30CD, 0x0000 ),  // KATAKANA LETTER NE
59     MAKE_PAIR( 0x30D2, 0x0000 ),  // KATAKANA LETTER HI
60     MAKE_PAIR( 0x30D3, 0x0000 ),  // KATAKANA LETTER BI
61     MAKE_PAIR( 0x30D4, 0x0000 ),  // KATAKANA LETTER PI
62     MAKE_PAIR( 0x30D8, 0x0000 ),  // KATAKANA LETTER HE
63     MAKE_PAIR( 0x30D9, 0x0000 ),  // KATAKANA LETTER BE
64     MAKE_PAIR( 0x30DA, 0x0000 ),  // KATAKANA LETTER PE
65     MAKE_PAIR( 0x30DF, 0x0000 ),  // KATAKANA LETTER MI
66     MAKE_PAIR( 0x30E1, 0x0000 ),  // KATAKANA LETTER ME
67     MAKE_PAIR( 0x30EA, 0x0000 ),  // KATAKANA LETTER RI
68     MAKE_PAIR( 0x30EC, 0x0000 ),  // KATAKANA LETTER RE
69     MAKE_PAIR( 0x30F0, 0x0000 ),  // KATAKANA LETTER WI
70     MAKE_PAIR( 0x30F1, 0x0000 ),  // KATAKANA LETTER WE
71     MAKE_PAIR( 0x30F6, 0x0000 ),  // KATAKANA LETTER SMALL KE
72     MAKE_PAIR( 0x30F8, 0x0000 ),  // KATAKANA LETTER VI
73     MAKE_PAIR( 0x30F9, 0x0000 )   // KATAKANA LETTER VE
74 };
75 
76 
77 
78 
79 OUString SAL_CALL
folding(const OUString & inStr,sal_Int32 startPos,sal_Int32 nCount,Sequence<sal_Int32> & offset)80 ignoreIandEfollowedByYa_ja_JP::folding( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount, Sequence< sal_Int32 >& offset )
81 {
82     // Create a string buffer which can hold nCount + 1 characters.
83     // The reference count is 0 now.
84     rtl_uString * newStr = x_rtl_uString_new_WithLength( nCount ); // defined in x_rtl_ustring.h
85     sal_Unicode * dst = newStr->buffer;
86     const sal_Unicode * src = inStr.getStr() + startPos;
87 
88     sal_Int32 *p = 0;
89     sal_Int32 position = 0;
90     if (useOffset) {
91         // Allocate nCount length to offset argument.
92         offset.realloc( nCount );
93         p = offset.getArray();
94         position = startPos;
95     }
96 
97     //
98     sal_Unicode previousChar = *src ++;
99     sal_Unicode currentChar;
100 
101     // One to one mapping
102     oneToOneMapping aTable(IandE, sizeof(IandE));
103 
104     // Translation
105     while (-- nCount > 0) {
106         currentChar = *src ++;
107 
108         // the character listed in above table + YA --> the character + A
109         if (currentChar == 0x30E3 ||   // KATAKANA LETTER SMALL YA
110                 currentChar == 0x30E4) {   // KATAKANA LETTER YA
111             if (aTable[ previousChar ] != previousChar) {
112                 if (useOffset) {
113                     *p ++ = position++;
114                     *p ++ = position++;
115                 }
116                 *dst ++ = previousChar;
117                 *dst ++ = 0x30A2;          // KATAKANA LETTER A
118                 previousChar = *src ++;
119                 nCount --;
120                 continue;
121             }
122         }
123 
124         if (useOffset)
125             *p ++ = position++;
126         *dst ++ = previousChar;
127         previousChar = currentChar;
128     }
129 
130     if (nCount == 0) {
131         if (useOffset)
132             *p = position;
133         *dst ++ = previousChar;
134     }
135 
136     *dst = (sal_Unicode) 0;
137 
138     newStr->length = sal_Int32(dst - newStr->buffer);
139     if (useOffset)
140         offset.realloc(newStr->length);
141     return OUString( newStr, SAL_NO_ACQUIRE ); // take over ownership of <newStr>
142 }
143 
144 } } } }
145