bump product version to 6.3.0.0.beta1
[LibreOffice.git] / i18npool / source / transliteration / ignoreDiacritics_CTL.cxx
blobd706f59f55281f689cafdaac285853ec0bb222d9
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/.
8 */
10 #include <rtl/ustrbuf.hxx>
11 #include <transliteration_Ignore.hxx>
12 #include <unicode/translit.h>
14 namespace i18npool {
16 ignoreDiacritics_CTL::ignoreDiacritics_CTL()
18 func = nullptr;
19 table = nullptr;
20 map = nullptr;
21 transliterationName = "ignoreDiacritics_CTL";
22 implementationName = "com.sun.star.i18n.Transliteration.ignoreDiacritics_CTL";
24 UErrorCode nStatus = U_ZERO_ERROR;
25 m_transliterator = icu::Transliterator::createInstance("NFD; [:M:] Remove; NFC",
26 UTRANS_FORWARD, nStatus);
27 if (U_FAILURE(nStatus))
28 m_transliterator = nullptr;
31 sal_Unicode SAL_CALL
32 ignoreDiacritics_CTL::transliterateChar2Char(sal_Unicode nInChar)
34 if (!m_transliterator)
35 throw css::uno::RuntimeException();
37 icu::UnicodeString aChar(nInChar);
38 m_transliterator->transliterate(aChar);
40 if (aChar.isEmpty())
41 return 0xffff; // Skip this character.
43 if (aChar.length() > 1)
44 return nInChar; // Don't know what to do here, return the original.
46 return aChar[0];
49 OUString
50 ignoreDiacritics_CTL::foldingImpl(const OUString& rInStr, sal_Int32 nStartPos,
51 sal_Int32 nCount, css::uno::Sequence<sal_Int32>& rOffset, bool useOffset)
53 if (!m_transliterator)
54 throw css::uno::RuntimeException();
56 if (nStartPos < 0 || nStartPos + nCount > rInStr.getLength())
57 throw css::uno::RuntimeException();
59 if (useOffset)
61 OUStringBuffer aOutBuf(nCount);
62 rOffset.realloc(nCount);
64 sal_Int32 nPosition = nStartPos;
65 sal_Int32 nOffset = 0;
66 while (nPosition < nStartPos + nCount)
68 sal_Int32 nIndex = nPosition;
69 UChar32 nChar = rInStr.iterateCodePoints(&nIndex);
70 icu::UnicodeString aUStr(nChar);
71 m_transliterator->transliterate(aUStr);
73 if (nOffset + aUStr.length() > rOffset.getLength())
74 rOffset.realloc(rOffset.getLength() + aUStr.length());
75 sal_Int32* pOffset = rOffset.getArray();
77 aOutBuf.append(reinterpret_cast<const sal_Unicode*>(aUStr.getBuffer()), aUStr.length());
79 for (const sal_Int32 nOffsetEnd = nOffset+aUStr.length(); nOffset < nOffsetEnd; nOffset++)
80 pOffset[nOffset] = nPosition;
82 nPosition = nIndex;
85 rOffset.realloc(aOutBuf.getLength());
86 return aOutBuf.makeStringAndClear();
88 else
90 icu::UnicodeString aUStr(reinterpret_cast<const UChar*>(rInStr.getStr()) + nStartPos, nCount);
91 m_transliterator->transliterate(aUStr);
92 return OUString(reinterpret_cast<const sal_Unicode*>(aUStr.getBuffer()), aUStr.length());
98 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */