1449ab281SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3449ab281SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4449ab281SAndrew Rist * or more contributor license agreements. See the NOTICE file
5449ab281SAndrew Rist * distributed with this work for additional information
6449ab281SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7449ab281SAndrew Rist * to you under the Apache License, Version 2.0 (the
8449ab281SAndrew Rist * "License"); you may not use this file except in compliance
9449ab281SAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11449ab281SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13449ab281SAndrew Rist * Unless required by applicable law or agreed to in writing,
14449ab281SAndrew Rist * software distributed under the License is distributed on an
15449ab281SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16449ab281SAndrew Rist * KIND, either express or implied. See the License for the
17449ab281SAndrew Rist * specific language governing permissions and limitations
18449ab281SAndrew Rist * under the License.
19cdf0e10cSrcweir *
20449ab281SAndrew Rist *************************************************************/
21449ab281SAndrew Rist
22449ab281SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_i18npool.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <transliteration_Numeric.hxx>
28cdf0e10cSrcweir #include <nativenumbersupplier.hxx>
29cdf0e10cSrcweir #include <defaultnumberingprovider.hxx>
30cdf0e10cSrcweir
31cdf0e10cSrcweir using namespace com::sun::star::uno;
32cdf0e10cSrcweir using namespace rtl;
33cdf0e10cSrcweir
34cdf0e10cSrcweir namespace com { namespace sun { namespace star { namespace i18n {
35cdf0e10cSrcweir
getType()36cdf0e10cSrcweir sal_Int16 SAL_CALL transliteration_Numeric::getType() throw(RuntimeException)
37cdf0e10cSrcweir {
38cdf0e10cSrcweir return TransliterationType::NUMERIC;
39cdf0e10cSrcweir }
40cdf0e10cSrcweir
41cdf0e10cSrcweir OUString SAL_CALL
folding(const OUString &,sal_Int32,sal_Int32,Sequence<sal_Int32> &)42cdf0e10cSrcweir transliteration_Numeric::folding( const OUString& /*inStr*/, sal_Int32 /*startPos*/, sal_Int32 /*nCount*/, Sequence< sal_Int32 >& /*offset*/ )
43cdf0e10cSrcweir throw(RuntimeException)
44cdf0e10cSrcweir {
45cdf0e10cSrcweir throw (new RuntimeException());
46cdf0e10cSrcweir }
47cdf0e10cSrcweir
48cdf0e10cSrcweir sal_Bool SAL_CALL
equals(const OUString &,sal_Int32,sal_Int32,sal_Int32 &,const OUString &,sal_Int32,sal_Int32,sal_Int32 &)49cdf0e10cSrcweir 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*/ )
50cdf0e10cSrcweir throw(RuntimeException)
51cdf0e10cSrcweir {
52cdf0e10cSrcweir throw (new RuntimeException());
53cdf0e10cSrcweir }
54cdf0e10cSrcweir
55cdf0e10cSrcweir Sequence< OUString > SAL_CALL
transliterateRange(const OUString &,const OUString &)56cdf0e10cSrcweir transliteration_Numeric::transliterateRange( const OUString& /*str1*/, const OUString& /*str2*/ )
57cdf0e10cSrcweir throw(RuntimeException)
58cdf0e10cSrcweir {
59cdf0e10cSrcweir throw (new RuntimeException());
60cdf0e10cSrcweir }
61cdf0e10cSrcweir
62cdf0e10cSrcweir
63cdf0e10cSrcweir #define isNumber(c) ((c) >= 0x30 && (c) <= 0x39)
64cdf0e10cSrcweir #define NUMBER_ZERO 0x30
65cdf0e10cSrcweir
66cdf0e10cSrcweir OUString SAL_CALL
transliterateBullet(const OUString & inStr,sal_Int32 startPos,sal_Int32 nCount,Sequence<sal_Int32> & offset)67cdf0e10cSrcweir transliteration_Numeric::transliterateBullet( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount,
68cdf0e10cSrcweir Sequence< sal_Int32 >& offset ) throw(RuntimeException)
69cdf0e10cSrcweir {
70cdf0e10cSrcweir sal_Int32 number = -1, j = 0, endPos = startPos + nCount;
71cdf0e10cSrcweir
72cdf0e10cSrcweir if (endPos > inStr.getLength())
73cdf0e10cSrcweir endPos = inStr.getLength();
74cdf0e10cSrcweir
75*4674bdb9SOliver-Rainer Wittmann rtl_uString* pStr = x_rtl_uString_new_WithLength( nCount ); // our x_rtl_ustring.h
76cdf0e10cSrcweir sal_Unicode* out = pStr->buffer;
77cdf0e10cSrcweir
78cdf0e10cSrcweir if (useOffset)
79cdf0e10cSrcweir offset.realloc(nCount);
80cdf0e10cSrcweir
81cdf0e10cSrcweir for (sal_Int32 i = startPos; i < endPos; i++) {
82cdf0e10cSrcweir if (i < endPos && isNumber(inStr[i])) {
83cdf0e10cSrcweir if (number == -1) {
84cdf0e10cSrcweir startPos = i;
85cdf0e10cSrcweir number = (inStr[i] - NUMBER_ZERO);
86cdf0e10cSrcweir } else {
87cdf0e10cSrcweir number = number * 10 + (inStr[i] - NUMBER_ZERO);
88cdf0e10cSrcweir }
89cdf0e10cSrcweir } else {
90cdf0e10cSrcweir if (number == 0) {
91cdf0e10cSrcweir if (useOffset)
92cdf0e10cSrcweir offset[j] = startPos;
93cdf0e10cSrcweir out[j++] = NUMBER_ZERO;
94cdf0e10cSrcweir } if (number > tableSize && !recycleSymbol) {
95cdf0e10cSrcweir for (sal_Int32 k = startPos; k < i; k++) {
96cdf0e10cSrcweir if (useOffset)
97cdf0e10cSrcweir offset[j] = k;
98cdf0e10cSrcweir out[j++] = inStr[k];
99cdf0e10cSrcweir }
100cdf0e10cSrcweir } else if (number > 0) {
101cdf0e10cSrcweir if (useOffset)
102cdf0e10cSrcweir offset[j] = startPos;
103cdf0e10cSrcweir out[j++] = table[--number % tableSize];
104cdf0e10cSrcweir } else if (i < endPos) {
105cdf0e10cSrcweir if (useOffset)
106cdf0e10cSrcweir offset[j] = i;
107cdf0e10cSrcweir out[j++] = inStr[i];
108cdf0e10cSrcweir }
109cdf0e10cSrcweir number = -1;
110cdf0e10cSrcweir }
111cdf0e10cSrcweir }
112cdf0e10cSrcweir out[j] = 0;
113cdf0e10cSrcweir
114cdf0e10cSrcweir if (useOffset)
115cdf0e10cSrcweir offset.realloc(j);
116cdf0e10cSrcweir
117*4674bdb9SOliver-Rainer Wittmann return OUString( pStr, SAL_NO_ACQUIRE ); // take over ownership of <pStr>
118cdf0e10cSrcweir }
119cdf0e10cSrcweir
120cdf0e10cSrcweir OUString SAL_CALL
transliterate(const OUString & inStr,sal_Int32 startPos,sal_Int32 nCount,Sequence<sal_Int32> & offset)121cdf0e10cSrcweir transliteration_Numeric::transliterate( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount,
122cdf0e10cSrcweir Sequence< sal_Int32 >& offset ) throw(RuntimeException)
123cdf0e10cSrcweir {
124cdf0e10cSrcweir if (tableSize)
125cdf0e10cSrcweir return transliterateBullet( inStr, startPos, nCount, offset);
126cdf0e10cSrcweir else
127cdf0e10cSrcweir return NativeNumberSupplier(useOffset).getNativeNumberString( inStr.copy(startPos, nCount), aLocale, nNativeNumberMode, offset );
128cdf0e10cSrcweir }
129cdf0e10cSrcweir
130cdf0e10cSrcweir sal_Unicode SAL_CALL
transliterateChar2Char(sal_Unicode inChar)131cdf0e10cSrcweir transliteration_Numeric::transliterateChar2Char( sal_Unicode inChar ) throw(RuntimeException, MultipleCharsOutputException)
132cdf0e10cSrcweir {
133cdf0e10cSrcweir if (tableSize) {
134cdf0e10cSrcweir if (isNumber(inChar)) {
135cdf0e10cSrcweir sal_Int16 number = inChar - NUMBER_ZERO;
136cdf0e10cSrcweir if (number <= tableSize || recycleSymbol)
137cdf0e10cSrcweir return table[--number % tableSize];
138cdf0e10cSrcweir }
139cdf0e10cSrcweir return inChar;
140cdf0e10cSrcweir }
141cdf0e10cSrcweir else
142cdf0e10cSrcweir return NativeNumberSupplier().getNativeNumberChar( inChar, aLocale, nNativeNumberMode );
143cdf0e10cSrcweir }
144cdf0e10cSrcweir
145cdf0e10cSrcweir } } } }
146