Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / i18npool / source / transliteration / ignoreKiKuFollowedBySa_ja_JP.cxx
blob913a3cf5f4ffe5f79df07cfc300a02d2ae052412
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <utility>
22 #include <comphelper/string.hxx>
23 #define TRANSLITERATION_KiKuFollowedBySa_ja_JP
24 #include <transliteration_Ignore.hxx>
26 using namespace com::sun::star::uno;
27 using namespace com::sun::star::lang;
29 using ::rtl::OUString;
31 namespace com { namespace sun { namespace star { namespace i18n {
33 OUString SAL_CALL
34 ignoreKiKuFollowedBySa_ja_JP::folding( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount, Sequence< sal_Int32 >& offset )
35 throw(RuntimeException)
37 // Create a string buffer which can hold nCount + 1 characters.
38 // The reference count is 1 now.
39 rtl_uString * newStr = comphelper::string::rtl_uString_alloc(nCount);
40 sal_Unicode * dst = newStr->buffer;
41 const sal_Unicode * src = inStr.getStr() + startPos;
43 sal_Int32 *p = 0;
44 sal_Int32 position = 0;
45 if (useOffset) {
46 // Allocate nCount length to offset argument.
47 offset.realloc( nCount );
48 p = offset.getArray();
49 position = startPos;
53 sal_Unicode previousChar = *src ++;
54 sal_Unicode currentChar;
56 // Translation
57 while (-- nCount > 0) {
58 currentChar = *src ++;
60 // KU + Sa-So --> KI + Sa-So
61 if (previousChar == 0x30AF ) { // KATAKANA LETTER KU
62 if (0x30B5 <= currentChar && // KATAKANA LETTER SA
63 currentChar <= 0x30BE) { // KATAKANA LETTER ZO
64 if (useOffset) {
65 *p ++ = position++;
66 *p ++ = position++;
68 *dst ++ = 0x30AD; // KATAKANA LETTER KI
69 *dst ++ = currentChar;
70 previousChar = *src ++;
71 nCount --;
72 continue;
76 if (useOffset)
77 *p ++ = position++;
78 *dst ++ = previousChar;
79 previousChar = currentChar;
82 if (nCount == 0) {
83 if (useOffset)
84 *p = position;
85 *dst ++ = previousChar;
88 *dst = (sal_Unicode) 0;
90 newStr->length = sal_Int32(dst - newStr->buffer);
91 if (useOffset)
92 offset.realloc(newStr->length);
93 return OUString(newStr, SAL_NO_ACQUIRE); // take ownership
96 } } } }
98 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */