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