1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: transliteration_Numeric.cxx,v $
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
;
41 namespace com
{ namespace sun
{ namespace star
{ namespace i18n
{
43 sal_Int16 SAL_CALL
transliteration_Numeric::getType() throw(RuntimeException
)
45 return TransliterationType::NUMERIC
;
49 transliteration_Numeric::folding( const OUString
& /*inStr*/, sal_Int32
/*startPos*/, sal_Int32
/*nCount*/, Sequence
< sal_Int32
>& /*offset*/ )
50 throw(RuntimeException
)
52 throw (new RuntimeException());
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
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
;
86 offset
.realloc(nCount
);
88 for (sal_Int32 i
= startPos
; i
< endPos
; i
++) {
89 if (i
< endPos
&& isNumber(inStr
[i
])) {
92 number
= (inStr
[i
] - NUMBER_ZERO
);
94 number
= number
* 10 + (inStr
[i
] - NUMBER_ZERO
);
100 out
[j
++] = NUMBER_ZERO
;
101 } if (number
> tableSize
&& !recycleSymbol
) {
102 for (sal_Int32 k
= startPos
; k
< i
; k
++) {
107 } else if (number
> 0) {
109 offset
[j
] = startPos
;
110 out
[j
++] = table
[--number
% tableSize
];
111 } else if (i
< endPos
) {
124 return OUString( pStr
, SAL_NO_ACQUIRE
);
128 transliteration_Numeric::transliterate( const OUString
& inStr
, sal_Int32 startPos
, sal_Int32 nCount
,
129 Sequence
< sal_Int32
>& offset
) throw(RuntimeException
)
132 return transliterateBullet( inStr
, startPos
, nCount
, offset
);
134 return NativeNumberSupplier(useOffset
).getNativeNumberString( inStr
.copy(startPos
, nCount
), aLocale
, nNativeNumberMode
, offset
);
138 transliteration_Numeric::transliterateChar2Char( sal_Unicode inChar
) throw(RuntimeException
, MultipleCharsOutputException
)
141 if (isNumber(inChar
)) {
142 sal_Int16 number
= inChar
- NUMBER_ZERO
;
143 if (number
<= tableSize
|| recycleSymbol
)
144 return table
[--number
% tableSize
];
149 return NativeNumberSupplier().getNativeNumberChar( inChar
, aLocale
, nNativeNumberMode
);