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 { 42 // Create a string buffer which can hold nCount + 1 characters. 43 // The reference count is 0 now. 44 rtl_uString * newStr = x_rtl_uString_new_WithLength( nCount ); // defined in x_rtl_ustring.h 45 sal_Unicode * dst = newStr->buffer; 46 const sal_Unicode * src = inStr.getStr() + startPos; 47 48 sal_Int32 *p = 0; 49 sal_Int32 position = 0; 50 if (useOffset) { 51 // Allocate nCount length to offset argument. 52 offset.realloc( nCount ); 53 p = offset.getArray(); 54 position = startPos; 55 } 56 57 // 58 sal_Unicode previousChar = *src ++; 59 sal_Unicode currentChar; 60 61 // Translation 62 while (-- nCount > 0) { 63 currentChar = *src ++; 64 65 // KU + Sa-So --> KI + Sa-So 66 if (previousChar == 0x30AF ) { // KATAKANA LETTER KU 67 if (0x30B5 <= currentChar && // KATAKANA LETTER SA 68 currentChar <= 0x30BE) { // KATAKANA LETTER ZO 69 if (useOffset) { 70 *p ++ = position++; 71 *p ++ = position++; 72 } 73 *dst ++ = 0x30AD; // KATAKANA LETTER KI 74 *dst ++ = currentChar; 75 previousChar = *src ++; 76 nCount --; 77 continue; 78 } 79 } 80 81 if (useOffset) 82 *p ++ = position++; 83 *dst ++ = previousChar; 84 previousChar = currentChar; 85 } 86 87 if (nCount == 0) { 88 if (useOffset) 89 *p = position; 90 *dst ++ = previousChar; 91 } 92 93 *dst = (sal_Unicode) 0; 94 95 newStr->length = sal_Int32(dst - newStr->buffer); 96 if (useOffset) 97 offset.realloc(newStr->length); 98 return OUString( newStr, SAL_NO_ACQUIRE ); // take over ownership of <newStr> 99 } 100 101 } } } } 102