Update ooo320-m1
[ooovba.git] / i18npool / source / ordinalsuffix / ordinalsuffix.cxx
blob5b50aaab4ed1941bd99215fbb4aa1f307c2902dd
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ordinalsuffix.cxx,v $
10 * $Revision: 1.3 $
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"
33 #include <comphelper/processfactory.hxx>
34 #include <string.h>
35 #include "ordinalsuffix.hxx"
38 using namespace ::com::sun::star::i18n;
39 using namespace ::com::sun::star::uno;
40 using namespace ::com::sun::star::lang;
41 using namespace ::rtl;
43 namespace com { namespace sun { namespace star { namespace i18n {
46 OrdinalSuffix::OrdinalSuffix(
47 const com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory >& rxMSF) :
48 _xServiceManager( rxMSF )
52 OrdinalSuffix::~OrdinalSuffix()
57 static OUString getOrdinalSuffixEn( sal_Int32 nNumber )
59 OUString retValue;
61 switch( labs( nNumber ) % 100 )
63 case 11: case 12: case 13:
64 retValue = OUString::createFromAscii( "th" );
65 break;
66 default:
67 switch( nNumber % 10 )
69 case 1:
70 retValue = OUString::createFromAscii( "st" );
71 break;
72 case 2:
73 retValue = OUString::createFromAscii( "nd" );
74 break;
75 case 3:
76 retValue = OUString::createFromAscii( "rd" );
77 break;
78 default:
79 retValue = OUString::createFromAscii( "th" );
80 break;
82 break;
85 return retValue;
89 OUString SAL_CALL OrdinalSuffix::getOrdinalSuffix( sal_Int32 nNumber,
90 const Locale &aLocale ) throw( RuntimeException )
92 OUString retValue;
94 if (aLocale.Language.equalsAsciiL("en",2))
95 retValue = getOrdinalSuffixEn( nNumber );
97 return retValue;
101 const sal_Char cOrdinalSuffix[] = "com.sun.star.i18n.OrdinalSuffix";
103 OUString SAL_CALL OrdinalSuffix::getImplementationName(void) throw( RuntimeException )
105 return OUString::createFromAscii(cOrdinalSuffix);
108 sal_Bool SAL_CALL OrdinalSuffix::supportsService( const OUString& rServiceName) throw( RuntimeException )
110 return !rServiceName.compareToAscii(cOrdinalSuffix);
113 Sequence< OUString > SAL_CALL OrdinalSuffix::getSupportedServiceNames(void) throw( RuntimeException )
115 Sequence< OUString > aRet(1);
116 aRet[0] = OUString::createFromAscii(cOrdinalSuffix);
117 return aRet;
120 } } } }