merged tag ooo/OOO330_m14
[LibreOffice.git] / i18npool / source / ordinalsuffix / ordinalsuffix.cxx
blobb577d72c5d0e86ae62db6913a84e66acefaf65bc
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_i18npool.hxx"
30 #include <comphelper/processfactory.hxx>
31 #include <string.h>
32 #include "ordinalsuffix.hxx"
35 using namespace ::com::sun::star::i18n;
36 using namespace ::com::sun::star::uno;
37 using namespace ::com::sun::star::lang;
38 using namespace ::rtl;
40 namespace com { namespace sun { namespace star { namespace i18n {
43 OrdinalSuffix::OrdinalSuffix(
44 const com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory >& rxMSF) :
45 _xServiceManager( rxMSF )
49 OrdinalSuffix::~OrdinalSuffix()
54 static OUString getOrdinalSuffixEn( sal_Int32 nNumber )
56 OUString retValue;
58 switch( labs( nNumber ) % 100 )
60 case 11: case 12: case 13:
61 retValue = OUString::createFromAscii( "th" );
62 break;
63 default:
64 switch( nNumber % 10 )
66 case 1:
67 retValue = OUString::createFromAscii( "st" );
68 break;
69 case 2:
70 retValue = OUString::createFromAscii( "nd" );
71 break;
72 case 3:
73 retValue = OUString::createFromAscii( "rd" );
74 break;
75 default:
76 retValue = OUString::createFromAscii( "th" );
77 break;
79 break;
82 return retValue;
86 OUString SAL_CALL OrdinalSuffix::getOrdinalSuffix( sal_Int32 nNumber,
87 const Locale &aLocale ) throw( RuntimeException )
89 OUString retValue;
91 if (aLocale.Language.equalsAsciiL("en",2))
92 retValue = getOrdinalSuffixEn( nNumber );
94 return retValue;
98 const sal_Char cOrdinalSuffix[] = "com.sun.star.i18n.OrdinalSuffix";
100 OUString SAL_CALL OrdinalSuffix::getImplementationName(void) throw( RuntimeException )
102 return OUString::createFromAscii(cOrdinalSuffix);
105 sal_Bool SAL_CALL OrdinalSuffix::supportsService( const OUString& rServiceName) throw( RuntimeException )
107 return !rServiceName.compareToAscii(cOrdinalSuffix);
110 Sequence< OUString > SAL_CALL OrdinalSuffix::getSupportedServiceNames(void) throw( RuntimeException )
112 Sequence< OUString > aRet(1);
113 aRet[0] = OUString::createFromAscii(cOrdinalSuffix);
114 return aRet;
117 } } } }