1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <com/sun/star/i18n/TransliterationType.hpp>
23 #include <transliteration_Numeric.hxx>
24 #include <nativenumbersupplier.hxx>
25 #include <rtl/ref.hxx>
27 using namespace com::sun::star::i18n
;
28 using namespace com::sun::star::uno
;
33 sal_Int16 SAL_CALL
transliteration_Numeric::getType()
35 return TransliterationType::NUMERIC
;
39 transliteration_Numeric::foldingImpl( const OUString
& /*inStr*/, sal_Int32
/*startPos*/, sal_Int32
/*nCount*/, Sequence
< sal_Int32
>& /*offset*/, bool )
41 throw RuntimeException();
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*/ )
47 throw RuntimeException();
50 Sequence
< OUString
> SAL_CALL
51 transliteration_Numeric::transliterateRange( const OUString
& /*str1*/, const OUString
& /*str2*/ )
53 throw RuntimeException();
57 #define isNumber(c) ((c) >= 0x30 && (c) <= 0x39)
58 #define NUMBER_ZERO 0x30
61 transliteration_Numeric::transliterateBullet( const OUString
& inStr
, sal_Int32 startPos
, sal_Int32 nCount
,
62 Sequence
< sal_Int32
>& offset
, bool useOffset
)
64 sal_Int32 number
= -1, j
= 0, endPos
= startPos
+ nCount
;
66 if (endPos
> inStr
.getLength())
67 endPos
= inStr
.getLength();
69 rtl_uString
* pStr
= rtl_uString_alloc(nCount
);
70 sal_Unicode
* out
= pStr
->buffer
;
73 offset
.realloc(nCount
);
75 for (sal_Int32 i
= startPos
; i
< endPos
; i
++) {
76 if (isNumber(inStr
[i
]))
80 number
= (inStr
[i
] - NUMBER_ZERO
);
82 number
= number
* 10 + (inStr
[i
] - NUMBER_ZERO
);
88 out
[j
++] = NUMBER_ZERO
;
89 } else if (number
> tableSize
&& !recycleSymbol
) {
90 for (sal_Int32 k
= startPos
; k
< i
; k
++) {
95 } else if (number
> 0) {
98 out
[j
++] = table
[--number
% tableSize
];
99 } else if (i
< endPos
) {
112 return OUString( pStr
, SAL_NO_ACQUIRE
);
116 transliteration_Numeric::transliterateImpl( const OUString
& inStr
, sal_Int32 startPos
, sal_Int32 nCount
,
117 Sequence
< sal_Int32
>& offset
, bool useOffset
)
120 return transliterateBullet( inStr
, startPos
, nCount
, offset
, useOffset
);
122 return rtl::Reference
<NativeNumberSupplierService
>(new NativeNumberSupplierService(useOffset
))->getNativeNumberString( inStr
.copy(startPos
, nCount
), aLocale
, nNativeNumberMode
, offset
);
126 transliteration_Numeric::transliterateChar2Char( sal_Unicode inChar
)
129 if (isNumber(inChar
)) {
130 sal_Int16 number
= inChar
- NUMBER_ZERO
;
131 if (number
<= tableSize
|| recycleSymbol
)
132 return table
[--number
% tableSize
];
137 return rtl::Reference
<NativeNumberSupplierService
>(new NativeNumberSupplierService
)->getNativeNumberChar( inChar
, aLocale
, nNativeNumberMode
);
142 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */