0024042: Performance improvements: Foundation Classes
[occt.git] / src / TCollection / TCollection_HExtendedString.cxx
1 // Copyright (c) 1992-1999 Matra Datavision
2 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 //
4 // The content of this file is subject to the Open CASCADE Technology Public
5 // License Version 6.5 (the "License"). You may not use the content of this file
6 // except in compliance with the License. Please obtain a copy of the License
7 // at http://www.opencascade.org and read it completely before using this file.
8 //
9 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 //
12 // The Original Code and all software distributed under the License is
13 // distributed on an "AS IS" basis, without warranty of any kind, and the
14 // Initial Developer hereby disclaims all such warranties, including without
15 // limitation, any warranties of merchantability, fitness for a particular
16 // purpose or non-infringement. Please see the License for the specific terms
17 // and conditions governing the rights and limitations under the License.
18
19 //Modified: C. LEYNADIER Nov,21 1997 (Token et ChangeString)
20
21 #include <TCollection_AsciiString.hxx>
22 #include <TCollection_HExtendedString.ixx>
23 #include <TCollection_HAsciiString.hxx>
24 #include <Standard_ExtCharacter.hxx>
25 #include <Standard_ExtString.hxx>
26
27 // ----------------------------------------------------------------------------
28 // Create
29 // ----------------------------------------------------------------------------
30 TCollection_HExtendedString::TCollection_HExtendedString(){}
31
32
33 // ----------------------------------------------------------------------------
34 // Create
35 // ----------------------------------------------------------------------------
36 TCollection_HExtendedString::TCollection_HExtendedString
37         (const Standard_CString message):myString(message)
38 {}
39
40 // ----------------------------------------------------------------------------
41 // Create
42 // ----------------------------------------------------------------------------
43 TCollection_HExtendedString::TCollection_HExtendedString
44         (const Standard_ExtString message):myString(message)
45 {}
46
47 // ----------------------------------------------------------------------------
48 // Create
49 // ----------------------------------------------------------------------------
50 TCollection_HExtendedString::TCollection_HExtendedString
51         (const Standard_ExtCharacter aChar):myString(aChar)
52 {}
53
54 // ----------------------------------------------------------------------------
55 // Create
56 // ----------------------------------------------------------------------------
57 TCollection_HExtendedString::TCollection_HExtendedString
58           (const Standard_Integer length,const Standard_ExtCharacter filler )
59           :myString(length,filler)
60 {}
61
62 // ----------------------------------------------------------------------------
63 // Create
64 // ----------------------------------------------------------------------------
65 TCollection_HExtendedString::TCollection_HExtendedString
66         (const TCollection_ExtendedString& astring):myString(astring)
67 {}
68
69 // ----------------------------------------------------------------------------
70 // Create
71 // ----------------------------------------------------------------------------
72 TCollection_HExtendedString::TCollection_HExtendedString
73         (const Handle(TCollection_HAsciiString)& astring)
74         :myString(astring->String())
75 {
76 }
77
78 // ----------------------------------------------------------------------------
79 // Create
80 // ----------------------------------------------------------------------------
81 TCollection_HExtendedString::TCollection_HExtendedString
82         (const Handle(TCollection_HExtendedString)& astring)
83         :myString(astring->ChangeString())
84 {
85 }
86
87 // ---------------------------------------------------------------------------
88 // AssignCat
89 // ----------------------------------------------------------------------------
90 void  TCollection_HExtendedString::AssignCat
91      (const Handle(TCollection_HExtendedString)& other) 
92 {
93    myString.AssignCat(other->ChangeString());
94 }
95
96 // ---------------------------------------------------------------------------
97 // Cat
98 // ----------------------------------------------------------------------------
99 Handle(TCollection_HExtendedString)  TCollection_HExtendedString::Cat
100      (const Handle(TCollection_HExtendedString)& other)  const
101 {
102    return new TCollection_HExtendedString(myString.Cat(other->ChangeString() ) );
103 }
104
105 // ----------------------------------------------------------------------------
106 // ChangeAll
107 // ----------------------------------------------------------------------------
108 void TCollection_HExtendedString::ChangeAll
109                        (const Standard_ExtCharacter aChar,
110                         const Standard_ExtCharacter NewChar)
111 {
112    myString.ChangeAll(aChar,NewChar);
113 }
114
115 // ----------------------------------------------------------------------------
116 // IsEmpty
117 // ----------------------------------------------------------------------------
118 Standard_Boolean TCollection_HExtendedString::IsEmpty() const
119 {
120    return (myString.Length() == 0);
121 }
122
123 // ----------------------------------------------------------------------------
124 // Clear
125 // ----------------------------------------------------------------------------
126 void TCollection_HExtendedString::Clear()
127 {
128    myString.Clear();
129 }
130
131 // ----------------------------------------------------------------------------
132 // Insert a Standard_ExtCharacter before 'where'th Standard_ExtCharacter
133 // ----------------------------------------------------------------------------
134 void TCollection_HExtendedString::Insert(const Standard_Integer where,
135                                  const Standard_ExtCharacter what)
136 {
137    myString.Insert(where,what);
138 }
139
140 // ----------------------------------------------------------------------------
141 // Insert
142 // ----------------------------------------------------------------------------
143 void TCollection_HExtendedString::Insert(const Standard_Integer where,
144                           const Handle(TCollection_HExtendedString)& what)
145 {
146    myString.Insert(where,what->ChangeString());
147 }
148
149 // ----------------------------------------------------------------------------
150 // IsLess
151 // ----------------------------------------------------------------------------
152 Standard_Boolean TCollection_HExtendedString::IsLess(
153         const Handle(TCollection_HExtendedString)& other) const
154 {
155    return myString.IsLess(other->ChangeString());
156 }
157
158 // ----------------------------------------------------------------------------
159 // IsGreater
160 // ----------------------------------------------------------------------------
161 Standard_Boolean TCollection_HExtendedString::IsGreater
162     (const Handle(TCollection_HExtendedString)& other) const
163 {
164    return myString.IsGreater(other->ChangeString());
165 }
166
167 // ----------------------------------------------------------------------------
168 // IsAscii
169 // ----------------------------------------------------------------------------
170 Standard_Boolean TCollection_HExtendedString::IsAscii() const 
171 {
172    return myString.IsAscii();
173 }
174
175 // ----------------------------------------------------------------------------
176 // Length
177 // ----------------------------------------------------------------------------
178 Standard_Integer TCollection_HExtendedString::Length() const
179 {
180    return myString.Length();
181 }
182
183 // ----------------------------------------------------------------------------
184 // Remove
185 // ----------------------------------------------------------------------------
186 void TCollection_HExtendedString::Remove (const Standard_Integer where,
187                                   const Standard_Integer ahowmany)
188 {
189    myString.Remove(where,ahowmany);
190 }
191
192 // ----------------------------------------------------------------------------
193 // RemoveAll
194 // ----------------------------------------------------------------------------
195 void TCollection_HExtendedString::RemoveAll(const Standard_ExtCharacter what)
196 {
197    myString.RemoveAll(what);
198 }
199
200 // ----------------------------------------------------------------------------
201 // SetValue
202 // ----------------------------------------------------------------------------
203 void TCollection_HExtendedString::SetValue(
204            const Standard_Integer where,const Standard_ExtCharacter what)
205 {
206    myString.SetValue(where,what);
207 }
208
209 // ----------------------------------------------------------------------------
210 // SetValue
211 // ---------------------------------------------------------------------------
212 void TCollection_HExtendedString::SetValue(const Standard_Integer where,
213                        const Handle(TCollection_HExtendedString)& what)
214 {
215    myString.SetValue(where, what->ChangeString());
216 }
217
218 // ----------------------------------------------------------------------------
219 // Split
220 // ----------------------------------------------------------------------------
221 Handle(TCollection_HExtendedString) TCollection_HExtendedString::Split
222               (const Standard_Integer where)
223 {
224    return new TCollection_HExtendedString(myString.Split(where));
225 }
226
227 // ----------------------------------------------------------------------------
228 // Search
229 // ----------------------------------------------------------------------------
230 Standard_Integer TCollection_HExtendedString::Search
231                        (const Handle(TCollection_HExtendedString)& what) const
232 {
233    return  myString.Search(what->ChangeString());
234 }
235
236 // ----------------------------------------------------------------------------
237 // SearchFromEnd
238 // ----------------------------------------------------------------------------
239 Standard_Integer TCollection_HExtendedString::SearchFromEnd
240                        (const Handle(TCollection_HExtendedString)& what) const
241 {
242    return  myString.SearchFromEnd(what->ChangeString());
243 }
244
245 // ----------------------------------------------------------------------------
246 // Token
247 // ----------------------------------------------------------------------------
248 Handle(TCollection_HExtendedString) TCollection_HExtendedString::Token
249          (const Standard_ExtString separators,const Standard_Integer whichone) const
250 {
251    return new TCollection_HExtendedString(myString.Token(separators,whichone));
252 }
253
254 // ----------------------------------------------------------------------------
255 // ToExtString
256 // ----------------------------------------------------------------------------
257 const Standard_ExtString TCollection_HExtendedString::ToExtString() const
258
259    return (myString.ToExtString());
260 }
261
262 // ----------------------------------------------------------------------------
263 // Trunc
264 // ----------------------------------------------------------------------------
265 void TCollection_HExtendedString::Trunc(const Standard_Integer ahowmany)
266 {
267    myString.Trunc(ahowmany);
268 }
269
270 // ----------------------------------------------------------------------------
271 // Value
272 // ----------------------------------------------------------------------------
273 Standard_ExtCharacter TCollection_HExtendedString::Value
274              (const Standard_Integer where) const
275 {
276    return myString.Value(where);
277 }
278
279 // ----------------------------------------------------------------------------
280 // String
281 // ----------------------------------------------------------------------------
282 const TCollection_ExtendedString& TCollection_HExtendedString::String() const
283 {
284   return myString;
285 }
286
287
288 //---------------------------------------------------------------------
289 // Print
290 //---------------------------------------------------------------------
291 void TCollection_HExtendedString::Print(Standard_OStream& S) const
292 {
293   S << "begin class HExtendedString "<<endl;
294   myString.Print(S);
295 }
296
297 // ----------------------------------------------------------------------------
298 // ShallowCopy
299 // ----------------------------------------------------------------------------
300 Handle(TCollection_HExtendedString) TCollection_HExtendedString::ShallowCopy() const
301 {
302    Handle(TCollection_HExtendedString) thecopy = 
303                 new TCollection_HExtendedString;
304    for (Standard_Integer i = 1 ; i <= Length() ; i++) 
305           thecopy->Insert(i,Value(i));
306    return thecopy;
307 }
308
309 //---------------------------------------------------------------------
310 // ShallowDump
311 //---------------------------------------------------------------------
312 void TCollection_HExtendedString::ShallowDump(Standard_OStream& S) const
313 {
314   S << "begin class HExtendedString "<<endl;
315   myString.Print(S);
316 }
317
318 // ----------------------------------------------------------------------------
319 // Issamestate
320 // ----------------------------------------------------------------------------
321 Standard_Boolean TCollection_HExtendedString::IsSameState
322    (const Handle(TCollection_HExtendedString)& other) const
323  {
324    Handle(TCollection_HExtendedString) H;
325    H = Handle(TCollection_HExtendedString)::DownCast(other);
326    return ( myString == H->ChangeString() );
327  }
328
329
330 TCollection_ExtendedString& TCollection_HExtendedString::ChangeString() const
331 {
332   return (TCollection_ExtendedString&)myString;
333 }