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 #define TRANSLITERATION_KiKuFollowedBySa_ja_JP
31 #include <transliteration_Ignore.hxx>
32 
33 using namespace com::sun::star::uno;
34 using namespace com::sun::star::lang;
35 using namespace rtl;
36 
37 namespace com { namespace sun { namespace star { namespace i18n {
38 
39 OUString SAL_CALL
40 ignoreKiKuFollowedBySa_ja_JP::folding( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount, Sequence< sal_Int32 >& offset )
41   throw(RuntimeException)
42 {
43     // Create a string buffer which can hold nCount + 1 characters.
44     // The reference count is 0 now.
45     rtl_uString * newStr = x_rtl_uString_new_WithLength( nCount ); // defined in x_rtl_ustring.h
46     sal_Unicode * dst = newStr->buffer;
47     const sal_Unicode * src = inStr.getStr() + startPos;
48 
49     sal_Int32 *p = 0;
50 	sal_Int32 position = 0;
51     if (useOffset) {
52         // Allocate nCount length to offset argument.
53         offset.realloc( nCount );
54         p = offset.getArray();
55         position = startPos;
56     }
57 
58     //
59     sal_Unicode previousChar = *src ++;
60     sal_Unicode currentChar;
61 
62     // Translation
63     while (-- nCount > 0) {
64         currentChar = *src ++;
65 
66         // KU + Sa-So --> KI + Sa-So
67         if (previousChar == 0x30AF ) { // KATAKANA LETTER KU
68             if (0x30B5 <= currentChar && // KATAKANA LETTER SA
69                     currentChar <= 0x30BE) { // KATAKANA LETTER ZO
70                 if (useOffset) {
71                     *p ++ = position++;
72                     *p ++ = position++;
73                 }
74                 *dst ++ = 0x30AD;          // KATAKANA LETTER KI
75                 *dst ++ = currentChar;
76                 previousChar = *src ++;
77                 nCount --;
78                 continue;
79             }
80         }
81 
82         if (useOffset)
83             *p ++ = position++;
84         *dst ++ = previousChar;
85         previousChar = currentChar;
86     }
87 
88     if (nCount == 0) {
89         if (useOffset)
90             *p = position;
91         *dst ++ = previousChar;
92     }
93 
94     *dst = (sal_Unicode) 0;
95 
96     newStr->length = sal_Int32(dst - newStr->buffer);
97     if (useOffset)
98         offset.realloc(newStr->length);
99     return OUString( newStr ); // defined in rtl/usrting. The reference count is increased from 0 to 1.
100 }
101 
102 } } } }
103