Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / i18npool / source / transliteration / transliteration_Numeric.cxx
blobeec4236092b8e37ea6d082761cceb7d41a5f32c5
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;
28 using ::rtl::OUString;
30 namespace com { namespace sun { namespace star { namespace i18n {
32 sal_Int16 SAL_CALL transliteration_Numeric::getType() throw(RuntimeException)
34 return TransliterationType::NUMERIC;
37 OUString SAL_CALL
38 transliteration_Numeric::folding( const OUString& /*inStr*/, sal_Int32 /*startPos*/, sal_Int32 /*nCount*/, Sequence< sal_Int32 >& /*offset*/ )
39 throw(RuntimeException)
41 throw (new RuntimeException());
44 sal_Bool SAL_CALL
45 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*/ )
46 throw(RuntimeException)
48 throw (new RuntimeException());
51 Sequence< OUString > SAL_CALL
52 transliteration_Numeric::transliterateRange( const OUString& /*str1*/, const OUString& /*str2*/ )
53 throw(RuntimeException)
55 throw (new RuntimeException());
59 #define isNumber(c) ((c) >= 0x30 && (c) <= 0x39)
60 #define NUMBER_ZERO 0x30
62 OUString SAL_CALL
63 transliteration_Numeric::transliterateBullet( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount,
64 Sequence< sal_Int32 >& offset ) throw(RuntimeException)
66 sal_Int32 number = -1, j = 0, endPos = startPos + nCount;
68 if (endPos > inStr.getLength())
69 endPos = inStr.getLength();
71 rtl_uString* pStr = comphelper::string::rtl_uString_alloc(nCount);
72 sal_Unicode* out = pStr->buffer;
74 if (useOffset)
75 offset.realloc(nCount);
77 for (sal_Int32 i = startPos; i < endPos; i++) {
78 if (i < endPos && isNumber(inStr[i])) {
79 if (number == -1) {
80 startPos = i;
81 number = (inStr[i] - NUMBER_ZERO);
82 } else {
83 number = number * 10 + (inStr[i] - NUMBER_ZERO);
85 } else {
86 if (number == 0) {
87 if (useOffset)
88 offset[j] = startPos;
89 out[j++] = NUMBER_ZERO;
90 } if (number > tableSize && !recycleSymbol) {
91 for (sal_Int32 k = startPos; k < i; k++) {
92 if (useOffset)
93 offset[j] = k;
94 out[j++] = inStr[k];
96 } else if (number > 0) {
97 if (useOffset)
98 offset[j] = startPos;
99 out[j++] = table[--number % tableSize];
100 } else if (i < endPos) {
101 if (useOffset)
102 offset[j] = i;
103 out[j++] = inStr[i];
105 number = -1;
108 out[j] = 0;
110 if (useOffset)
111 offset.realloc(j);
113 return OUString( pStr, SAL_NO_ACQUIRE );
116 OUString SAL_CALL
117 transliteration_Numeric::transliterate( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount,
118 Sequence< sal_Int32 >& offset ) throw(RuntimeException)
120 if (tableSize)
121 return transliterateBullet( inStr, startPos, nCount, offset);
122 else
123 return NativeNumberSupplier(useOffset).getNativeNumberString( inStr.copy(startPos, nCount), aLocale, nNativeNumberMode, offset );
126 sal_Unicode SAL_CALL
127 transliteration_Numeric::transliterateChar2Char( sal_Unicode inChar ) throw(RuntimeException, MultipleCharsOutputException)
129 if (tableSize) {
130 if (isNumber(inChar)) {
131 sal_Int16 number = inChar - NUMBER_ZERO;
132 if (number <= tableSize || recycleSymbol)
133 return table[--number % tableSize];
135 return inChar;
137 else
138 return NativeNumberSupplier().getNativeNumberChar( inChar, aLocale, nNativeNumberMode );
141 } } } }
143 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */