1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_i18npool.hxx"
26 #include <comphelper/processfactory.hxx>
27 #include <string.h>
28 #include "ordinalsuffix.hxx"
29 
30 
31 using namespace ::com::sun::star::i18n;
32 using namespace ::com::sun::star::uno;
33 using namespace ::com::sun::star::lang;
34 using namespace ::rtl;
35 
36 namespace com { namespace sun { namespace star { namespace i18n {
37 
38 
OrdinalSuffix(const com::sun::star::uno::Reference<com::sun::star::lang::XMultiServiceFactory> & rxMSF)39 OrdinalSuffix::OrdinalSuffix(
40         const com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory >& rxMSF) :
41     _xServiceManager( rxMSF )
42 {
43 }
44 
~OrdinalSuffix()45 OrdinalSuffix::~OrdinalSuffix()
46 {
47 }
48 
49 
getOrdinalSuffixEn(sal_Int32 nNumber)50 static OUString getOrdinalSuffixEn( sal_Int32 nNumber )
51 {
52     OUString retValue;
53 
54     switch( labs( nNumber ) % 100 )
55     {
56         case 11: case 12: case 13:
57             retValue = OUString::createFromAscii( "th" );
58             break;
59         default:
60             switch( nNumber % 10 )
61             {
62                 case 1:
63                     retValue = OUString::createFromAscii( "st" );
64                     break;
65                 case 2:
66                     retValue = OUString::createFromAscii( "nd" );
67                     break;
68                 case 3:
69                     retValue = OUString::createFromAscii( "rd" );
70                     break;
71                 default:
72                     retValue = OUString::createFromAscii( "th" );
73                     break;
74             }
75             break;
76     }
77 
78     return retValue;
79 }
80 
81 
getOrdinalSuffix(sal_Int32 nNumber,const Locale & aLocale)82 OUString SAL_CALL OrdinalSuffix::getOrdinalSuffix( sal_Int32 nNumber,
83         const Locale &aLocale ) throw( RuntimeException )
84 {
85     OUString retValue;
86 
87     if (aLocale.Language.equalsAsciiL("en",2))
88         retValue = getOrdinalSuffixEn( nNumber );
89 
90     return retValue;
91 }
92 
93 
94 const sal_Char cOrdinalSuffix[] = "com.sun.star.i18n.OrdinalSuffix";
95 
getImplementationName(void)96 OUString SAL_CALL OrdinalSuffix::getImplementationName(void) throw( RuntimeException )
97 {
98     return OUString::createFromAscii(cOrdinalSuffix);
99 }
100 
supportsService(const OUString & rServiceName)101 sal_Bool SAL_CALL OrdinalSuffix::supportsService( const OUString& rServiceName) throw( RuntimeException )
102 {
103     return !rServiceName.compareToAscii(cOrdinalSuffix);
104 }
105 
getSupportedServiceNames(void)106 Sequence< OUString > SAL_CALL OrdinalSuffix::getSupportedServiceNames(void) throw( RuntimeException )
107 {
108     Sequence< OUString > aRet(1);
109     aRet[0] = OUString::createFromAscii(cOrdinalSuffix);
110     return aRet;
111 }
112 
113 } } } }
114