1 /* Copyright (c) MediaArea.net SARL. All Rights Reserved.
2 *
3 * Use of this source code is governed by a zlib-style license that can
4 * be found in the License.txt file in the root of the source tree.
5 */
6
7 //---------------------------------------------------------------------------
8 #include "ZenLib/PreComp.h"
9 #ifdef __BORLANDC__
10 #pragma hdrstop
11 #endif
12 //---------------------------------------------------------------------------
13
14 //---------------------------------------------------------------------------
15 #include "ZenLib/Conf_Internal.h"
16 //---------------------------------------------------------------------------
17
18 //---------------------------------------------------------------------------
19 #ifdef ZENLIB_USEWX
20 #include <wx/strconv.h>
21 #endif //ZENLIB_USEWX
22 #include <algorithm>
23 #include "ZenLib/Translation.h"
24 using namespace std;
25 //---------------------------------------------------------------------------
26
27 namespace ZenLib
28 {
29
30 //***************************************************************************
31 // Constructors/Destructor
32 //***************************************************************************
33
34 //---------------------------------------------------------------------------
35 // Constructors
Translation()36 Translation::Translation()
37 : std::map<ZenLib::Ztring, ZenLib::Ztring> ()
38 {
39 Separator[0]=EOL;
40 Separator[1]=__T(";");
41 }
42
Translation(const Ztring & Source)43 Translation::Translation(const Ztring &Source)
44 {
45 Separator[0]=EOL;
46 Separator[1]=__T(";");
47 Write(Source);
48 }
49
Translation(const Char * Source)50 Translation::Translation(const Char *Source)
51 {
52 Separator[0]=EOL;
53 Separator[1]=__T(";");
54 Write(Source);
55 }
56
57 #ifdef _UNICODE
Translation(const char * S)58 Translation::Translation (const char* S)
59 {
60 Separator[0]=EOL;
61 Separator[1]=__T(";");
62 Write(Ztring(S));
63 }
64 #endif
65
66 //***************************************************************************
67 // In/Out
68 //***************************************************************************
69
70 //---------------------------------------------------------------------------
71 // Get
Get() const72 Ztring Translation::Get () const
73 {
74 Ztring ToReturn;
75 const_iterator Temp=begin();
76 while (Temp!=end())
77 {
78 ToReturn+=Temp->first;
79 ToReturn+=Separator[1];
80 ToReturn+=Temp->second;
81 ToReturn+=Separator[0];
82 ++Temp;
83 }
84 return ToReturn;
85 }
86
Get(const Ztring & Value)87 const Ztring &Translation::Get (const Ztring &Value)
88 {
89 iterator Pos=find(Value);
90 if (Pos==end())
91 operator[](Value)=Value;
92 return operator[](Value);
93 }
94
Get(const Ztring & Value,const Ztring & Default)95 Ztring Translation::Get (const Ztring &Value, const Ztring &Default)
96 {
97 iterator Pos=find(Value);
98 if (Pos==end())
99 operator[](Value)=Default;
100 return operator[](Value);
101 }
102
103 //---------------------------------------------------------------------------
104 // Set
Write(const Ztring & NewLanguage)105 void Translation::Write(const Ztring &NewLanguage)
106 {
107 clear();
108
109 if (NewLanguage.empty())
110 return;
111
112 size_t Pos1=0, Pos2_EOL=0, Pos2_Separator=0;
113
114 while (Pos2_EOL!=(size_t)-1)
115 {
116 Pos2_EOL=NewLanguage.find(__T('\n'), Pos1);
117 Pos2_Separator=NewLanguage.find(__T(';'), Pos1);
118 if (Pos2_Separator<Pos2_EOL)
119 {
120 operator[](NewLanguage.substr(Pos1, Pos2_Separator-Pos1))=NewLanguage.substr(Pos2_Separator+1, Pos2_EOL-Pos2_Separator-1);
121 }
122 Pos1=Pos2_EOL+1;
123 }
124 }
125
126 //---------------------------------------------------------------------------
127 // Set
Write(const Ztring & Value,const Ztring & NewLanguage)128 void Translation::Write(const Ztring &Value, const Ztring &NewLanguage)
129 {
130 operator[](Value)=NewLanguage;
131 }
132
133 //***************************************************************************
134 // Configuration
135 //***************************************************************************
136
137 //---------------------------------------------------------------------------
138 // Separator
Separator_Set(size_type Level,const Ztring & NewSeparator)139 void Translation::Separator_Set (size_type Level, const Ztring &NewSeparator)
140 {
141 if (Level>1)
142 return;
143
144 Separator[Level]=NewSeparator;
145 }
146
147 //***************************************************************************
148 // C++
149 //***************************************************************************
150
151 } //namespace
152