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 
25 // MARKER(update_precomp.py): autogen include statement, do not remove
26 #include "precompiled_svtools.hxx"
27 #include <svtools/svtdata.hxx>
28 #include <svtools/svtools.hrc>
29 #include <svtools/collatorres.hxx>
30 
31 // -------------------------------------------------------------------------
32 //
33 //  wrapper for locale specific translations data of collator algorithm
34 //
35 // -------------------------------------------------------------------------
36 
37 class CollatorRessourceData
38 {
39 	friend class CollatorRessource;
40 	private: /* data */
41 		String 			ma_Name;
42 		String 			ma_Translation;
43 	private: /* member functions */
CollatorRessourceData()44 		CollatorRessourceData () {}
45 	public:
CollatorRessourceData(const String & r_Algorithm,const String & r_Translation)46 		CollatorRessourceData ( const String &r_Algorithm, const String &r_Translation)
47 				    : ma_Name (r_Algorithm), ma_Translation (r_Translation) {}
48 
GetAlgorithm() const49 		const String&	GetAlgorithm () const { return ma_Name; }
50 
GetTranslation() const51 		const String&	GetTranslation () const { return ma_Translation; }
52 
~CollatorRessourceData()53 		~CollatorRessourceData () {}
54 
operator =(const CollatorRessourceData & r_From)55 		CollatorRessourceData& operator= (const CollatorRessourceData& r_From)
56 		{
57 			ma_Name 		= r_From.GetAlgorithm();
58 			ma_Translation 	= r_From.GetTranslation();
59 			return *this;
60 		}
61 };
62 
63 // -------------------------------------------------------------------------
64 //
65 //  implementation of the collator-algorithm-name translation
66 //
67 // -------------------------------------------------------------------------
68 
69 #define COLLATOR_RESSOURCE_COUNT (STR_SVT_COLLATE_END - STR_SVT_COLLATE_START + 1)
70 
CollatorRessource()71 CollatorRessource::CollatorRessource()
72 {
73 	mp_Data = new CollatorRessourceData[COLLATOR_RESSOURCE_COUNT];
74 
75 	#define ASCSTR(str) String(RTL_CONSTASCII_USTRINGPARAM(str))
76 	#define RESSTR(rid) String(SvtResId(rid))
77 
78 
79 	mp_Data[0] = CollatorRessourceData (ASCSTR("alphanumeric"), RESSTR(STR_SVT_COLLATE_ALPHANUMERIC));
80 	mp_Data[1] = CollatorRessourceData (ASCSTR("charset"), RESSTR(STR_SVT_COLLATE_CHARSET));
81 	mp_Data[2] = CollatorRessourceData (ASCSTR("dict"), RESSTR(STR_SVT_COLLATE_DICTIONARY));
82 	mp_Data[3] = CollatorRessourceData (ASCSTR("normal"), RESSTR(STR_SVT_COLLATE_NORMAL));
83 	mp_Data[4] = CollatorRessourceData (ASCSTR("pinyin"), RESSTR(STR_SVT_COLLATE_PINYIN));
84 	mp_Data[5] = CollatorRessourceData (ASCSTR("radical"), RESSTR(STR_SVT_COLLATE_RADICAL));
85 	mp_Data[6] = CollatorRessourceData (ASCSTR("stroke"), RESSTR(STR_SVT_COLLATE_STROKE));
86 	mp_Data[7] = CollatorRessourceData (ASCSTR("unicode"), RESSTR(STR_SVT_COLLATE_UNICODE));
87 	mp_Data[8] = CollatorRessourceData (ASCSTR("zhuyin"), RESSTR(STR_SVT_COLLATE_ZHUYIN));
88 	mp_Data[9] = CollatorRessourceData (ASCSTR("phonebook"), RESSTR(STR_SVT_COLLATE_PHONEBOOK));
89 	mp_Data[10] = CollatorRessourceData (ASCSTR("phonetic (alphanumeric first)"), RESSTR(STR_SVT_COLLATE_PHONETIC_F));
90 	mp_Data[11] = CollatorRessourceData (ASCSTR("phonetic (alphanumeric last)"), RESSTR(STR_SVT_COLLATE_PHONETIC_L));
91 }
92 
~CollatorRessource()93 CollatorRessource::~CollatorRessource()
94 {
95 	delete[] mp_Data;
96 }
97 
98 const String&
GetTranslation(const String & r_Algorithm)99 CollatorRessource::GetTranslation (const String &r_Algorithm)
100 {
101 	xub_StrLen nIndex = r_Algorithm.Search('.');
102 	String aLocaleFreeAlgorithm;
103 
104 	if (nIndex == STRING_NOTFOUND)
105 	{
106 		aLocaleFreeAlgorithm = r_Algorithm;
107 	}
108 	else
109 	{
110 		nIndex += 1;
111 		aLocaleFreeAlgorithm = String(r_Algorithm, nIndex, r_Algorithm.Len() - nIndex);
112 	}
113 
114 	for (sal_uInt32 i = 0; i < COLLATOR_RESSOURCE_COUNT; i++)
115 	{
116 		if (aLocaleFreeAlgorithm == mp_Data[i].GetAlgorithm())
117 			return mp_Data[i].GetTranslation();
118 	}
119 
120 	return r_Algorithm;
121 }
122 
123