1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 
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"
33 
34 
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;
39 
40 namespace com { namespace sun { namespace star { namespace i18n {
41 
42 
43 OrdinalSuffix::OrdinalSuffix(
44         const com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory >& rxMSF) :
45     _xServiceManager( rxMSF )
46 {
47 }
48 
49 OrdinalSuffix::~OrdinalSuffix()
50 {
51 }
52 
53 
54 static OUString getOrdinalSuffixEn( sal_Int32 nNumber )
55 {
56     OUString retValue;
57 
58     switch( labs( nNumber ) % 100 )
59     {
60         case 11: case 12: case 13:
61             retValue = OUString::createFromAscii( "th" );
62             break;
63         default:
64             switch( nNumber % 10 )
65             {
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;
78             }
79             break;
80     }
81 
82     return retValue;
83 }
84 
85 
86 OUString SAL_CALL OrdinalSuffix::getOrdinalSuffix( sal_Int32 nNumber,
87         const Locale &aLocale ) throw( RuntimeException )
88 {
89     OUString retValue;
90 
91     if (aLocale.Language.equalsAsciiL("en",2))
92         retValue = getOrdinalSuffixEn( nNumber );
93 
94     return retValue;
95 }
96 
97 
98 const sal_Char cOrdinalSuffix[] = "com.sun.star.i18n.OrdinalSuffix";
99 
100 OUString SAL_CALL OrdinalSuffix::getImplementationName(void) throw( RuntimeException )
101 {
102     return OUString::createFromAscii(cOrdinalSuffix);
103 }
104 
105 sal_Bool SAL_CALL OrdinalSuffix::supportsService( const OUString& rServiceName) throw( RuntimeException )
106 {
107     return !rServiceName.compareToAscii(cOrdinalSuffix);
108 }
109 
110 Sequence< OUString > SAL_CALL OrdinalSuffix::getSupportedServiceNames(void) throw( RuntimeException )
111 {
112     Sequence< OUString > aRet(1);
113     aRet[0] = OUString::createFromAscii(cOrdinalSuffix);
114     return aRet;
115 }
116 
117 } } } }
118