xref: /AOO41X/main/svtools/source/control/collatorres.cxx (revision 79aad27f7f29270c03e208e3d687e8e3850af11d)
1*5900e8ecSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*5900e8ecSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*5900e8ecSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*5900e8ecSAndrew Rist  * distributed with this work for additional information
6*5900e8ecSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*5900e8ecSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*5900e8ecSAndrew Rist  * "License"); you may not use this file except in compliance
9*5900e8ecSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*5900e8ecSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*5900e8ecSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*5900e8ecSAndrew Rist  * software distributed under the License is distributed on an
15*5900e8ecSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*5900e8ecSAndrew Rist  * KIND, either express or implied.  See the License for the
17*5900e8ecSAndrew Rist  * specific language governing permissions and limitations
18*5900e8ecSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*5900e8ecSAndrew Rist  *************************************************************/
21*5900e8ecSAndrew Rist 
22*5900e8ecSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir 
25cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
26cdf0e10cSrcweir #include "precompiled_svtools.hxx"
27cdf0e10cSrcweir #include <svtools/svtdata.hxx>
28cdf0e10cSrcweir #include <svtools/svtools.hrc>
29cdf0e10cSrcweir #include <svtools/collatorres.hxx>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir // -------------------------------------------------------------------------
32cdf0e10cSrcweir //
33cdf0e10cSrcweir //  wrapper for locale specific translations data of collator algorithm
34cdf0e10cSrcweir //
35cdf0e10cSrcweir // -------------------------------------------------------------------------
36cdf0e10cSrcweir 
37cdf0e10cSrcweir class CollatorRessourceData
38cdf0e10cSrcweir {
39cdf0e10cSrcweir 	friend class CollatorRessource;
40cdf0e10cSrcweir 	private: /* data */
41cdf0e10cSrcweir 		String 			ma_Name;
42cdf0e10cSrcweir 		String 			ma_Translation;
43cdf0e10cSrcweir 	private: /* member functions */
CollatorRessourceData()44cdf0e10cSrcweir 		CollatorRessourceData () {}
45cdf0e10cSrcweir 	public:
CollatorRessourceData(const String & r_Algorithm,const String & r_Translation)46cdf0e10cSrcweir 		CollatorRessourceData ( const String &r_Algorithm, const String &r_Translation)
47cdf0e10cSrcweir 				    : ma_Name (r_Algorithm), ma_Translation (r_Translation) {}
48cdf0e10cSrcweir 
GetAlgorithm() const49cdf0e10cSrcweir 		const String&	GetAlgorithm () const { return ma_Name; }
50cdf0e10cSrcweir 
GetTranslation() const51cdf0e10cSrcweir 		const String&	GetTranslation () const { return ma_Translation; }
52cdf0e10cSrcweir 
~CollatorRessourceData()53cdf0e10cSrcweir 		~CollatorRessourceData () {}
54cdf0e10cSrcweir 
operator =(const CollatorRessourceData & r_From)55cdf0e10cSrcweir 		CollatorRessourceData& operator= (const CollatorRessourceData& r_From)
56cdf0e10cSrcweir 		{
57cdf0e10cSrcweir 			ma_Name 		= r_From.GetAlgorithm();
58cdf0e10cSrcweir 			ma_Translation 	= r_From.GetTranslation();
59cdf0e10cSrcweir 			return *this;
60cdf0e10cSrcweir 		}
61cdf0e10cSrcweir };
62cdf0e10cSrcweir 
63cdf0e10cSrcweir // -------------------------------------------------------------------------
64cdf0e10cSrcweir //
65cdf0e10cSrcweir //  implementation of the collator-algorithm-name translation
66cdf0e10cSrcweir //
67cdf0e10cSrcweir // -------------------------------------------------------------------------
68cdf0e10cSrcweir 
69cdf0e10cSrcweir #define COLLATOR_RESSOURCE_COUNT (STR_SVT_COLLATE_END - STR_SVT_COLLATE_START + 1)
70cdf0e10cSrcweir 
CollatorRessource()71cdf0e10cSrcweir CollatorRessource::CollatorRessource()
72cdf0e10cSrcweir {
73cdf0e10cSrcweir 	mp_Data = new CollatorRessourceData[COLLATOR_RESSOURCE_COUNT];
74cdf0e10cSrcweir 
75cdf0e10cSrcweir 	#define ASCSTR(str) String(RTL_CONSTASCII_USTRINGPARAM(str))
76cdf0e10cSrcweir 	#define RESSTR(rid) String(SvtResId(rid))
77cdf0e10cSrcweir 
78cdf0e10cSrcweir 
79cdf0e10cSrcweir 	mp_Data[0] = CollatorRessourceData (ASCSTR("alphanumeric"), RESSTR(STR_SVT_COLLATE_ALPHANUMERIC));
80cdf0e10cSrcweir 	mp_Data[1] = CollatorRessourceData (ASCSTR("charset"), RESSTR(STR_SVT_COLLATE_CHARSET));
81cdf0e10cSrcweir 	mp_Data[2] = CollatorRessourceData (ASCSTR("dict"), RESSTR(STR_SVT_COLLATE_DICTIONARY));
82cdf0e10cSrcweir 	mp_Data[3] = CollatorRessourceData (ASCSTR("normal"), RESSTR(STR_SVT_COLLATE_NORMAL));
83cdf0e10cSrcweir 	mp_Data[4] = CollatorRessourceData (ASCSTR("pinyin"), RESSTR(STR_SVT_COLLATE_PINYIN));
84cdf0e10cSrcweir 	mp_Data[5] = CollatorRessourceData (ASCSTR("radical"), RESSTR(STR_SVT_COLLATE_RADICAL));
85cdf0e10cSrcweir 	mp_Data[6] = CollatorRessourceData (ASCSTR("stroke"), RESSTR(STR_SVT_COLLATE_STROKE));
86cdf0e10cSrcweir 	mp_Data[7] = CollatorRessourceData (ASCSTR("unicode"), RESSTR(STR_SVT_COLLATE_UNICODE));
87cdf0e10cSrcweir 	mp_Data[8] = CollatorRessourceData (ASCSTR("zhuyin"), RESSTR(STR_SVT_COLLATE_ZHUYIN));
88cdf0e10cSrcweir 	mp_Data[9] = CollatorRessourceData (ASCSTR("phonebook"), RESSTR(STR_SVT_COLLATE_PHONEBOOK));
89cdf0e10cSrcweir 	mp_Data[10] = CollatorRessourceData (ASCSTR("phonetic (alphanumeric first)"), RESSTR(STR_SVT_COLLATE_PHONETIC_F));
90cdf0e10cSrcweir 	mp_Data[11] = CollatorRessourceData (ASCSTR("phonetic (alphanumeric last)"), RESSTR(STR_SVT_COLLATE_PHONETIC_L));
91cdf0e10cSrcweir }
92cdf0e10cSrcweir 
~CollatorRessource()93cdf0e10cSrcweir CollatorRessource::~CollatorRessource()
94cdf0e10cSrcweir {
95cdf0e10cSrcweir 	delete[] mp_Data;
96cdf0e10cSrcweir }
97cdf0e10cSrcweir 
98cdf0e10cSrcweir const String&
GetTranslation(const String & r_Algorithm)99cdf0e10cSrcweir CollatorRessource::GetTranslation (const String &r_Algorithm)
100cdf0e10cSrcweir {
101cdf0e10cSrcweir 	xub_StrLen nIndex = r_Algorithm.Search('.');
102cdf0e10cSrcweir 	String aLocaleFreeAlgorithm;
103cdf0e10cSrcweir 
104cdf0e10cSrcweir 	if (nIndex == STRING_NOTFOUND)
105cdf0e10cSrcweir 	{
106cdf0e10cSrcweir 		aLocaleFreeAlgorithm = r_Algorithm;
107cdf0e10cSrcweir 	}
108cdf0e10cSrcweir 	else
109cdf0e10cSrcweir 	{
110cdf0e10cSrcweir 		nIndex += 1;
111cdf0e10cSrcweir 		aLocaleFreeAlgorithm = String(r_Algorithm, nIndex, r_Algorithm.Len() - nIndex);
112cdf0e10cSrcweir 	}
113cdf0e10cSrcweir 
114cdf0e10cSrcweir 	for (sal_uInt32 i = 0; i < COLLATOR_RESSOURCE_COUNT; i++)
115cdf0e10cSrcweir 	{
116cdf0e10cSrcweir 		if (aLocaleFreeAlgorithm == mp_Data[i].GetAlgorithm())
117cdf0e10cSrcweir 			return mp_Data[i].GetTranslation();
118cdf0e10cSrcweir 	}
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 	return r_Algorithm;
121cdf0e10cSrcweir }
122cdf0e10cSrcweir 
123