merge the formfield patch from ooo-build
[ooovba.git] / i18npool / source / transliteration / transliteration_Numeric.cxx
blob4afe81caac01ececc996eb291cb44818a1ce8709
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: transliteration_Numeric.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_i18npool.hxx"
34 #include <transliteration_Numeric.hxx>
35 #include <nativenumbersupplier.hxx>
36 #include <defaultnumberingprovider.hxx>
38 using namespace com::sun::star::uno;
39 using namespace rtl;
41 namespace com { namespace sun { namespace star { namespace i18n {
43 sal_Int16 SAL_CALL transliteration_Numeric::getType() throw(RuntimeException)
45 return TransliterationType::NUMERIC;
48 OUString SAL_CALL
49 transliteration_Numeric::folding( const OUString& /*inStr*/, sal_Int32 /*startPos*/, sal_Int32 /*nCount*/, Sequence< sal_Int32 >& /*offset*/ )
50 throw(RuntimeException)
52 throw (new RuntimeException());
55 sal_Bool SAL_CALL
56 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*/ )
57 throw(RuntimeException)
59 throw (new RuntimeException());
62 Sequence< OUString > SAL_CALL
63 transliteration_Numeric::transliterateRange( const OUString& /*str1*/, const OUString& /*str2*/ )
64 throw(RuntimeException)
66 throw (new RuntimeException());
70 #define isNumber(c) ((c) >= 0x30 && (c) <= 0x39)
71 #define NUMBER_ZERO 0x30
73 OUString SAL_CALL
74 transliteration_Numeric::transliterateBullet( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount,
75 Sequence< sal_Int32 >& offset ) throw(RuntimeException)
77 sal_Int32 number = -1, j = 0, endPos = startPos + nCount;
79 if (endPos > inStr.getLength())
80 endPos = inStr.getLength();
82 rtl_uString* pStr = x_rtl_uString_new_WithLength( nCount, 1 ); // our x_rtl_ustring.h
83 sal_Unicode* out = pStr->buffer;
85 if (useOffset)
86 offset.realloc(nCount);
88 for (sal_Int32 i = startPos; i < endPos; i++) {
89 if (i < endPos && isNumber(inStr[i])) {
90 if (number == -1) {
91 startPos = i;
92 number = (inStr[i] - NUMBER_ZERO);
93 } else {
94 number = number * 10 + (inStr[i] - NUMBER_ZERO);
96 } else {
97 if (number == 0) {
98 if (useOffset)
99 offset[j] = startPos;
100 out[j++] = NUMBER_ZERO;
101 } if (number > tableSize && !recycleSymbol) {
102 for (sal_Int32 k = startPos; k < i; k++) {
103 if (useOffset)
104 offset[j] = k;
105 out[j++] = inStr[k];
107 } else if (number > 0) {
108 if (useOffset)
109 offset[j] = startPos;
110 out[j++] = table[--number % tableSize];
111 } else if (i < endPos) {
112 if (useOffset)
113 offset[j] = i;
114 out[j++] = inStr[i];
116 number = -1;
119 out[j] = 0;
121 if (useOffset)
122 offset.realloc(j);
124 return OUString( pStr, SAL_NO_ACQUIRE );
127 OUString SAL_CALL
128 transliteration_Numeric::transliterate( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount,
129 Sequence< sal_Int32 >& offset ) throw(RuntimeException)
131 if (tableSize)
132 return transliterateBullet( inStr, startPos, nCount, offset);
133 else
134 return NativeNumberSupplier(useOffset).getNativeNumberString( inStr.copy(startPos, nCount), aLocale, nNativeNumberMode, offset );
137 sal_Unicode SAL_CALL
138 transliteration_Numeric::transliterateChar2Char( sal_Unicode inChar ) throw(RuntimeException, MultipleCharsOutputException)
140 if (tableSize) {
141 if (isNumber(inChar)) {
142 sal_Int16 number = inChar - NUMBER_ZERO;
143 if (number <= tableSize || recycleSymbol)
144 return table[--number % tableSize];
146 return inChar;
148 else
149 return NativeNumberSupplier().getNativeNumberChar( inChar, aLocale, nNativeNumberMode );
152 } } } }