Bump version to 4.3-4
[LibreOffice.git] / i18npool / source / transliteration / transliteration_Numeric.cxx
blob78d33e3feec81beca7161987e0af2c7e10e84f28
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 <transliteration_Numeric.hxx>
22 #include <nativenumbersupplier.hxx>
23 #include <defaultnumberingprovider.hxx>
24 #include <comphelper/string.hxx>
26 using namespace com::sun::star::uno;
29 namespace com { namespace sun { namespace star { namespace i18n {
31 sal_Int16 SAL_CALL transliteration_Numeric::getType() throw(RuntimeException, std::exception)
33 return TransliterationType::NUMERIC;
36 OUString SAL_CALL
37 transliteration_Numeric::folding( const OUString& /*inStr*/, sal_Int32 /*startPos*/, sal_Int32 /*nCount*/, Sequence< sal_Int32 >& /*offset*/ )
38 throw(RuntimeException, std::exception)
40 throw RuntimeException();
43 sal_Bool SAL_CALL
44 transliteration_Numeric::equals( const OUString& /*str1*/, sal_Int32 /*pos1*/, sal_Int32 /*nCount1*/, sal_Int32& /*nMatch1*/, const OUString& /*str2*/, sal_Int32 /*pos2*/, sal_Int32 /*nCount2*/, sal_Int32& /*nMatch2*/ )
45 throw(RuntimeException, std::exception)
47 throw RuntimeException();
50 Sequence< OUString > SAL_CALL
51 transliteration_Numeric::transliterateRange( const OUString& /*str1*/, const OUString& /*str2*/ )
52 throw(RuntimeException, std::exception)
54 throw RuntimeException();
58 #define isNumber(c) ((c) >= 0x30 && (c) <= 0x39)
59 #define NUMBER_ZERO 0x30
61 OUString SAL_CALL
62 transliteration_Numeric::transliterateBullet( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount,
63 Sequence< sal_Int32 >& offset ) throw(RuntimeException)
65 sal_Int32 number = -1, j = 0, endPos = startPos + nCount;
67 if (endPos > inStr.getLength())
68 endPos = inStr.getLength();
70 rtl_uString* pStr = rtl_uString_alloc(nCount);
71 sal_Unicode* out = pStr->buffer;
73 if (useOffset)
74 offset.realloc(nCount);
76 for (sal_Int32 i = startPos; i < endPos; i++) {
77 if (i < endPos && isNumber(inStr[i])) {
78 if (number == -1) {
79 startPos = i;
80 number = (inStr[i] - NUMBER_ZERO);
81 } else {
82 number = number * 10 + (inStr[i] - NUMBER_ZERO);
84 } else {
85 if (number == 0) {
86 if (useOffset)
87 offset[j] = startPos;
88 out[j++] = NUMBER_ZERO;
89 } if (number > tableSize && !recycleSymbol) {
90 for (sal_Int32 k = startPos; k < i; k++) {
91 if (useOffset)
92 offset[j] = k;
93 out[j++] = inStr[k];
95 } else if (number > 0) {
96 if (useOffset)
97 offset[j] = startPos;
98 out[j++] = table[--number % tableSize];
99 } else if (i < endPos) {
100 if (useOffset)
101 offset[j] = i;
102 out[j++] = inStr[i];
104 number = -1;
107 out[j] = 0;
109 if (useOffset)
110 offset.realloc(j);
112 return OUString( pStr, SAL_NO_ACQUIRE );
115 OUString SAL_CALL
116 transliteration_Numeric::transliterate( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount,
117 Sequence< sal_Int32 >& offset ) throw(RuntimeException, std::exception)
119 if (tableSize)
120 return transliterateBullet( inStr, startPos, nCount, offset);
121 else
122 return NativeNumberSupplier(useOffset).getNativeNumberString( inStr.copy(startPos, nCount), aLocale, nNativeNumberMode, offset );
125 sal_Unicode SAL_CALL
126 transliteration_Numeric::transliterateChar2Char( sal_Unicode inChar ) throw(RuntimeException, MultipleCharsOutputException, std::exception)
128 if (tableSize) {
129 if (isNumber(inChar)) {
130 sal_Int16 number = inChar - NUMBER_ZERO;
131 if (number <= tableSize || recycleSymbol)
132 return table[--number % tableSize];
134 return inChar;
136 else
137 return NativeNumberSupplier().getNativeNumberChar( inChar, aLocale, nNativeNumberMode );
140 } } } }
142 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */