1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_i18npool.hxx"
30 
31 // prevent internal compiler error with MSVC6SP3
32 #include <utility>
33 
34 #define TRANSLITERATION_KiKuFollowedBySa_ja_JP
35 #include <transliteration_Ignore.hxx>
36 
37 using namespace com::sun::star::uno;
38 using namespace com::sun::star::lang;
39 using namespace rtl;
40 
41 namespace com { namespace sun { namespace star { namespace i18n {
42 
43 OUString SAL_CALL
44 ignoreKiKuFollowedBySa_ja_JP::folding( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount, Sequence< sal_Int32 >& offset )
45   throw(RuntimeException)
46 {
47     // Create a string buffer which can hold nCount + 1 characters.
48     // The reference count is 0 now.
49     rtl_uString * newStr = x_rtl_uString_new_WithLength( nCount ); // defined in x_rtl_ustring.h
50     sal_Unicode * dst = newStr->buffer;
51     const sal_Unicode * src = inStr.getStr() + startPos;
52 
53     sal_Int32 *p = 0;
54 	sal_Int32 position = 0;
55     if (useOffset) {
56         // Allocate nCount length to offset argument.
57         offset.realloc( nCount );
58         p = offset.getArray();
59         position = startPos;
60     }
61 
62     //
63     sal_Unicode previousChar = *src ++;
64     sal_Unicode currentChar;
65 
66     // Translation
67     while (-- nCount > 0) {
68         currentChar = *src ++;
69 
70         // KU + Sa-So --> KI + Sa-So
71         if (previousChar == 0x30AF ) { // KATAKANA LETTER KU
72             if (0x30B5 <= currentChar && // KATAKANA LETTER SA
73                     currentChar <= 0x30BE) { // KATAKANA LETTER ZO
74                 if (useOffset) {
75                     *p ++ = position++;
76                     *p ++ = position++;
77                 }
78                 *dst ++ = 0x30AD;          // KATAKANA LETTER KI
79                 *dst ++ = currentChar;
80                 previousChar = *src ++;
81                 nCount --;
82                 continue;
83             }
84         }
85 
86         if (useOffset)
87             *p ++ = position++;
88         *dst ++ = previousChar;
89         previousChar = currentChar;
90     }
91 
92     if (nCount == 0) {
93         if (useOffset)
94             *p = position;
95         *dst ++ = previousChar;
96     }
97 
98     *dst = (sal_Unicode) 0;
99 
100     newStr->length = sal_Int32(dst - newStr->buffer);
101     if (useOffset)
102         offset.realloc(newStr->length);
103     return OUString( newStr ); // defined in rtl/usrting. The reference count is increased from 0 to 1.
104 }
105 
106 } } } }
107