1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim:set ts=2 sw=2 sts=2 et cindent: */
3 : /* ***** BEGIN LICENSE BLOCK *****
4 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 : *
6 : * The contents of this file are subject to the Mozilla Public License Version
7 : * 1.1 (the "License"); you may not use this file except in compliance with
8 : * the License. You may obtain a copy of the License at
9 : * http://www.mozilla.org/MPL/
10 : *
11 : * Software distributed under the License is distributed on an "AS IS" basis,
12 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 : * for the specific language governing rights and limitations under the
14 : * License.
15 : *
16 : * The Original Code is Mozilla.
17 : *
18 : * The Initial Developer of the Original Code is IBM Corporation.
19 : * Portions created by IBM Corporation are Copyright (C) 2003
20 : * IBM Corporation. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * Rick Gessner <rickg@netscape.com> (original author)
24 : * Scott Collins <scc@mozilla.org>
25 : * Darin Fisher <darin@meer.net>
26 : *
27 : * Alternatively, the contents of this file may be used under the terms of
28 : * either the GNU General Public License Version 2 or later (the "GPL"), or
29 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 : * in which case the provisions of the GPL or the LGPL are applicable instead
31 : * of those above. If you wish to allow use of your version of this file only
32 : * under the terms of either the GPL or the LGPL, and not to allow others to
33 : * use your version of this file under the terms of the MPL, indicate your
34 : * decision by deleting the provisions above and replace them with the notice
35 : * and other provisions required by the GPL or the LGPL. If you do not delete
36 : * the provisions above, a recipient may use your version of this file under
37 : * the terms of any one of the MPL, the GPL or the LGPL.
38 : *
39 : * ***** END LICENSE BLOCK ***** */
40 :
41 :
42 : /**
43 : * This is the canonical null-terminated string class. All subclasses
44 : * promise null-terminated storage. Instances of this class allocate
45 : * strings on the heap.
46 : *
47 : * NAMES:
48 : * nsString for wide characters
49 : * nsCString for narrow characters
50 : *
51 : * This class is also known as nsAFlat[C]String, where "flat" is used
52 : * to denote a null-terminated string.
53 : */
54 : class nsTString_CharT : public nsTSubstring_CharT
55 63667708 : {
56 : public:
57 :
58 : typedef nsTString_CharT self_type;
59 :
60 : public:
61 :
62 : /**
63 : * constructors
64 : */
65 :
66 12188597 : nsTString_CharT()
67 12188597 : : substring_type() {}
68 :
69 : explicit
70 347445 : nsTString_CharT( const char_type* data, size_type length = size_type(-1) )
71 347445 : : substring_type()
72 : {
73 347445 : Assign(data, length);
74 347445 : }
75 :
76 2431425 : nsTString_CharT( const self_type& str )
77 2431425 : : substring_type()
78 : {
79 2431425 : Assign(str);
80 2431425 : }
81 :
82 5909 : nsTString_CharT( const substring_tuple_type& tuple )
83 5909 : : substring_type()
84 : {
85 5909 : Assign(tuple);
86 5909 : }
87 :
88 : explicit
89 5880413 : nsTString_CharT( const substring_type& readable )
90 5880413 : : substring_type()
91 : {
92 5880412 : Assign(readable);
93 5880414 : }
94 :
95 :
96 : // |operator=| does not inherit, so we must define our own
97 6 : self_type& operator=( char_type c ) { Assign(c); return *this; }
98 73170 : self_type& operator=( const char_type* data ) { Assign(data); return *this; }
99 114738 : self_type& operator=( const self_type& str ) { Assign(str); return *this; }
100 773603 : self_type& operator=( const substring_type& str ) { Assign(str); return *this; }
101 4796 : self_type& operator=( const substring_tuple_type& tuple ) { Assign(tuple); return *this; }
102 :
103 : /**
104 : * returns the null-terminated string
105 : */
106 :
107 9598407 : const char_type* get() const
108 : {
109 9598407 : return mData;
110 : }
111 :
112 :
113 : /**
114 : * returns character at specified index.
115 : *
116 : * NOTE: unlike nsTSubstring::CharAt, this function allows you to index
117 : * the null terminator character.
118 : */
119 :
120 1733196 : char_type CharAt( index_type i ) const
121 : {
122 1733196 : NS_ASSERTION(i <= mLength, "index exceeds allowable range");
123 1733196 : return mData[i];
124 : }
125 :
126 1544828 : char_type operator[]( index_type i ) const
127 : {
128 1544828 : return CharAt(i);
129 : }
130 :
131 :
132 : #if MOZ_STRING_WITH_OBSOLETE_API
133 :
134 :
135 : /**
136 : * Search for the given substring within this string.
137 : *
138 : * @param aString is substring to be sought in this
139 : * @param aIgnoreCase selects case sensitivity
140 : * @param aOffset tells us where in this string to start searching
141 : * @param aCount tells us how far from the offset we are to search. Use
142 : * -1 to search the whole string.
143 : * @return offset in string, or kNotFound
144 : */
145 :
146 : PRInt32 Find( const nsCString& aString, bool aIgnoreCase=false, PRInt32 aOffset=0, PRInt32 aCount=-1 ) const;
147 : PRInt32 Find( const char* aString, bool aIgnoreCase=false, PRInt32 aOffset=0, PRInt32 aCount=-1 ) const;
148 :
149 : #ifdef CharT_is_PRUnichar
150 : PRInt32 Find( const nsAFlatString& aString, PRInt32 aOffset=0, PRInt32 aCount=-1 ) const;
151 : PRInt32 Find( const PRUnichar* aString, PRInt32 aOffset=0, PRInt32 aCount=-1 ) const;
152 : #endif
153 :
154 :
155 : /**
156 : * This methods scans the string backwards, looking for the given string
157 : *
158 : * @param aString is substring to be sought in this
159 : * @param aIgnoreCase tells us whether or not to do caseless compare
160 : * @param aOffset tells us where in this string to start searching.
161 : * Use -1 to search from the end of the string.
162 : * @param aCount tells us how many iterations to make starting at the
163 : * given offset.
164 : * @return offset in string, or kNotFound
165 : */
166 :
167 : PRInt32 RFind( const nsCString& aString, bool aIgnoreCase=false, PRInt32 aOffset=-1, PRInt32 aCount=-1 ) const;
168 : PRInt32 RFind( const char* aCString, bool aIgnoreCase=false, PRInt32 aOffset=-1, PRInt32 aCount=-1 ) const;
169 :
170 : #ifdef CharT_is_PRUnichar
171 : PRInt32 RFind( const nsAFlatString& aString, PRInt32 aOffset=-1, PRInt32 aCount=-1 ) const;
172 : PRInt32 RFind( const PRUnichar* aString, PRInt32 aOffset=-1, PRInt32 aCount=-1 ) const;
173 : #endif
174 :
175 :
176 : /**
177 : * Search for given char within this string
178 : *
179 : * @param aChar is the character to search for
180 : * @param aOffset tells us where in this string to start searching
181 : * @param aCount tells us how far from the offset we are to search.
182 : * Use -1 to search the whole string.
183 : * @return offset in string, or kNotFound
184 : */
185 :
186 : // PRInt32 FindChar( PRUnichar aChar, PRInt32 aOffset=0, PRInt32 aCount=-1 ) const;
187 : PRInt32 RFindChar( PRUnichar aChar, PRInt32 aOffset=-1, PRInt32 aCount=-1 ) const;
188 :
189 :
190 : /**
191 : * This method searches this string for the first character found in
192 : * the given string.
193 : *
194 : * @param aString contains set of chars to be found
195 : * @param aOffset tells us where in this string to start searching
196 : * (counting from left)
197 : * @return offset in string, or kNotFound
198 : */
199 :
200 : PRInt32 FindCharInSet( const char* aString, PRInt32 aOffset=0 ) const;
201 697 : PRInt32 FindCharInSet( const self_type& aString, PRInt32 aOffset=0 ) const
202 : {
203 697 : return FindCharInSet(aString.get(), aOffset);
204 : }
205 :
206 : #ifdef CharT_is_PRUnichar
207 : PRInt32 FindCharInSet( const PRUnichar* aString, PRInt32 aOffset=0 ) const;
208 : #endif
209 :
210 :
211 : /**
212 : * This method searches this string for the last character found in
213 : * the given string.
214 : *
215 : * @param aString contains set of chars to be found
216 : * @param aOffset tells us where in this string to start searching
217 : * (counting from left)
218 : * @return offset in string, or kNotFound
219 : */
220 :
221 : PRInt32 RFindCharInSet( const char_type* aString, PRInt32 aOffset=-1 ) const;
222 : PRInt32 RFindCharInSet( const self_type& aString, PRInt32 aOffset=-1 ) const
223 : {
224 : return RFindCharInSet(aString.get(), aOffset);
225 : }
226 :
227 :
228 : /**
229 : * Compares a given string to this string.
230 : *
231 : * @param aString is the string to be compared
232 : * @param aIgnoreCase tells us how to treat case
233 : * @param aCount tells us how many chars to compare
234 : * @return -1,0,1
235 : */
236 :
237 : #ifdef CharT_is_char
238 : PRInt32 Compare( const char* aString, bool aIgnoreCase=false, PRInt32 aCount=-1 ) const;
239 : #endif
240 :
241 :
242 : /**
243 : * Equality check between given string and this string.
244 : *
245 : * @param aString is the string to check
246 : * @param aIgnoreCase tells us how to treat case
247 : * @param aCount tells us how many chars to compare
248 : * @return boolean
249 : */
250 : #ifdef CharT_is_char
251 29883 : bool EqualsIgnoreCase( const char* aString, PRInt32 aCount=-1 ) const {
252 29883 : return Compare(aString, true, aCount) == 0;
253 : }
254 : #else
255 : bool EqualsIgnoreCase( const char* aString, PRInt32 aCount=-1 ) const;
256 :
257 :
258 : #endif // !CharT_is_PRUnichar
259 :
260 : /**
261 : * Perform string to double-precision float conversion.
262 : *
263 : * @param aErrorCode will contain error if one occurs
264 : * @return double-precision float rep of string value
265 : */
266 : double ToDouble( PRInt32* aErrorCode ) const;
267 :
268 : /**
269 : * Perform string to single-precision float conversion.
270 : *
271 : * @param aErrorCode will contain error if one occurs
272 : * @return single-precision float rep of string value
273 : */
274 0 : float ToFloat( PRInt32* aErrorCode ) const {
275 0 : return (float)ToDouble(aErrorCode);
276 : }
277 :
278 :
279 : /**
280 : * Perform string to int conversion.
281 : * @param aErrorCode will contain error if one occurs
282 : * @param aRadix tells us which radix to assume; kAutoDetect tells us to determine the radix for you.
283 : * @return int rep of string value, and possible (out) error code
284 : */
285 : PRInt32 ToInteger( PRInt32* aErrorCode, PRUint32 aRadix=kRadix10 ) const;
286 1253 : PRInt32 ToInteger( nsresult* aErrorCode, PRUint32 aRadix=kRadix10 ) const {
287 1253 : return ToInteger(reinterpret_cast<PRInt32*>(aErrorCode), aRadix);
288 : }
289 :
290 : /**
291 : * |Left|, |Mid|, and |Right| are annoying signatures that seem better almost
292 : * any _other_ way than they are now. Consider these alternatives
293 : *
294 : * aWritable = aReadable.Left(17); // ...a member function that returns a |Substring|
295 : * aWritable = Left(aReadable, 17); // ...a global function that returns a |Substring|
296 : * Left(aReadable, 17, aWritable); // ...a global function that does the assignment
297 : *
298 : * as opposed to the current signature
299 : *
300 : * aReadable.Left(aWritable, 17); // ...a member function that does the assignment
301 : *
302 : * or maybe just stamping them out in favor of |Substring|, they are just duplicate functionality
303 : *
304 : * aWritable = Substring(aReadable, 0, 17);
305 : */
306 :
307 : size_type Mid( self_type& aResult, PRUint32 aStartPos, PRUint32 aCount ) const;
308 :
309 12431 : size_type Left( self_type& aResult, size_type aCount ) const
310 : {
311 12431 : return Mid(aResult, 0, aCount);
312 : }
313 :
314 8 : size_type Right( self_type& aResult, size_type aCount ) const
315 : {
316 8 : aCount = NS_MIN(mLength, aCount);
317 8 : return Mid(aResult, mLength - aCount, aCount);
318 : }
319 :
320 :
321 : /**
322 : * Set a char inside this string at given index
323 : *
324 : * @param aChar is the char you want to write into this string
325 : * @param anIndex is the ofs where you want to write the given char
326 : * @return TRUE if successful
327 : */
328 :
329 : bool SetCharAt( PRUnichar aChar, PRUint32 aIndex );
330 :
331 :
332 : /**
333 : * These methods are used to remove all occurrences of the
334 : * characters found in aSet from this string.
335 : *
336 : * @param aSet -- characters to be cut from this
337 : */
338 : void StripChars( const char* aSet );
339 :
340 :
341 : /**
342 : * This method strips whitespace throughout the string.
343 : */
344 : void StripWhitespace();
345 :
346 :
347 : /**
348 : * swaps occurence of 1 string for another
349 : */
350 :
351 : void ReplaceChar( char_type aOldChar, char_type aNewChar );
352 : void ReplaceChar( const char* aSet, char_type aNewChar );
353 : void ReplaceSubstring( const self_type& aTarget, const self_type& aNewValue);
354 : void ReplaceSubstring( const char_type* aTarget, const char_type* aNewValue);
355 :
356 :
357 : /**
358 : * This method trims characters found in aTrimSet from
359 : * either end of the underlying string.
360 : *
361 : * @param aSet -- contains chars to be trimmed from both ends
362 : * @param aEliminateLeading
363 : * @param aEliminateTrailing
364 : * @param aIgnoreQuotes -- if true, causes surrounding quotes to be ignored
365 : * @return this
366 : */
367 : void Trim( const char* aSet, bool aEliminateLeading=true, bool aEliminateTrailing=true, bool aIgnoreQuotes=false );
368 :
369 : /**
370 : * This method strips whitespace from string.
371 : * You can control whether whitespace is yanked from start and end of
372 : * string as well.
373 : *
374 : * @param aEliminateLeading controls stripping of leading ws
375 : * @param aEliminateTrailing controls stripping of trailing ws
376 : */
377 : void CompressWhitespace( bool aEliminateLeading=true, bool aEliminateTrailing=true );
378 :
379 :
380 : /**
381 : * assign/append/insert with _LOSSY_ conversion
382 : */
383 :
384 : void AssignWithConversion( const nsTAString_IncompatibleCharT& aString );
385 : void AssignWithConversion( const incompatible_char_type* aData, PRInt32 aLength=-1 );
386 :
387 : void AppendWithConversion( const nsTAString_IncompatibleCharT& aString );
388 : void AppendWithConversion( const incompatible_char_type* aData, PRInt32 aLength=-1 );
389 :
390 : #endif // !MOZ_STRING_WITH_OBSOLETE_API
391 :
392 :
393 : protected:
394 :
395 : explicit
396 : nsTString_CharT( PRUint32 flags )
397 : : substring_type(flags) {}
398 :
399 : // allow subclasses to initialize fields directly
400 44255102 : nsTString_CharT( char_type* data, size_type length, PRUint32 flags )
401 44255102 : : substring_type(data, length, flags) {}
402 : };
403 :
404 :
405 : class nsTFixedString_CharT : public nsTString_CharT
406 16018657 : {
407 : public:
408 :
409 : typedef nsTFixedString_CharT self_type;
410 : typedef nsTFixedString_CharT fixed_string_type;
411 :
412 : public:
413 :
414 : /**
415 : * @param data
416 : * fixed-size buffer to be used by the string (the contents of
417 : * this buffer may be modified by the string)
418 : * @param storageSize
419 : * the size of the fixed buffer
420 : * @param length (optional)
421 : * the length of the string already contained in the buffer
422 : */
423 :
424 : nsTFixedString_CharT( char_type* data, size_type storageSize )
425 : : string_type(data, PRUint32(char_traits::length(data)), F_TERMINATED | F_FIXED | F_CLASS_FIXED)
426 : , mFixedCapacity(storageSize - 1)
427 : , mFixedBuf(data)
428 : {}
429 :
430 17333739 : nsTFixedString_CharT( char_type* data, size_type storageSize, size_type length )
431 : : string_type(data, length, F_TERMINATED | F_FIXED | F_CLASS_FIXED)
432 : , mFixedCapacity(storageSize - 1)
433 17333739 : , mFixedBuf(data)
434 : {
435 : // null-terminate
436 17333727 : mFixedBuf[length] = char_type(0);
437 17333727 : }
438 :
439 : // |operator=| does not inherit, so we must define our own
440 : self_type& operator=( char_type c ) { Assign(c); return *this; }
441 2018 : self_type& operator=( const char_type* data ) { Assign(data); return *this; }
442 0 : self_type& operator=( const substring_type& str ) { Assign(str); return *this; }
443 : self_type& operator=( const substring_tuple_type& tuple ) { Assign(tuple); return *this; }
444 :
445 : protected:
446 :
447 : friend class nsTSubstring_CharT;
448 :
449 : size_type mFixedCapacity;
450 : char_type *mFixedBuf;
451 : };
452 :
453 :
454 : /**
455 : * nsTAutoString_CharT
456 : *
457 : * Subclass of nsTString_CharT that adds support for stack-based string
458 : * allocation. It is normally not a good idea to use this class on the
459 : * heap, because it will allocate space which may be wasted if the string
460 : * it contains is significantly smaller or any larger than 64 characters.
461 : *
462 : * NAMES:
463 : * nsAutoString for wide characters
464 : * nsCAutoString for narrow characters
465 : */
466 : class NS_STACK_CLASS nsTAutoString_CharT : public nsTFixedString_CharT
467 16013425 : {
468 : public:
469 :
470 : typedef nsTAutoString_CharT self_type;
471 :
472 : public:
473 :
474 : /**
475 : * constructors
476 : */
477 :
478 10810640 : nsTAutoString_CharT()
479 10810640 : : fixed_string_type(mStorage, kDefaultStorageSize, 0)
480 10810638 : {}
481 :
482 : explicit
483 0 : nsTAutoString_CharT( char_type c )
484 0 : : fixed_string_type(mStorage, kDefaultStorageSize, 0)
485 : {
486 0 : Assign(c);
487 0 : }
488 :
489 : explicit
490 6370763 : nsTAutoString_CharT( const char_type* data, size_type length = size_type(-1) )
491 6370763 : : fixed_string_type(mStorage, kDefaultStorageSize, 0)
492 : {
493 6370762 : Assign(data, length);
494 6370763 : }
495 :
496 70044 : nsTAutoString_CharT( const self_type& str )
497 70044 : : fixed_string_type(mStorage, kDefaultStorageSize, 0)
498 : {
499 70044 : Assign(str);
500 70044 : }
501 :
502 : explicit
503 63231 : nsTAutoString_CharT( const substring_type& str )
504 63231 : : fixed_string_type(mStorage, kDefaultStorageSize, 0)
505 : {
506 63231 : Assign(str);
507 63231 : }
508 :
509 13701 : nsTAutoString_CharT( const substring_tuple_type& tuple )
510 13701 : : fixed_string_type(mStorage, kDefaultStorageSize, 0)
511 : {
512 13701 : Assign(tuple);
513 13701 : }
514 :
515 : // |operator=| does not inherit, so we must define our own
516 5 : self_type& operator=( char_type c ) { Assign(c); return *this; }
517 1951 : self_type& operator=( const char_type* data ) { Assign(data); return *this; }
518 18864 : self_type& operator=( const self_type& str ) { Assign(str); return *this; }
519 75018 : self_type& operator=( const substring_type& str ) { Assign(str); return *this; }
520 14673 : self_type& operator=( const substring_tuple_type& tuple ) { Assign(tuple); return *this; }
521 :
522 : enum { kDefaultStorageSize = 64 };
523 :
524 : private:
525 :
526 : char_type mStorage[kDefaultStorageSize];
527 : };
528 :
529 :
530 : //
531 : // nsAutoString stores pointers into itself which are invalidated when an
532 : // nsTArray is resized, so nsTArray must not be instantiated with nsAutoString
533 : // elements!
534 : //
535 : template<class E> class nsTArrayElementTraits;
536 : template<>
537 : class nsTArrayElementTraits<nsTAutoString_CharT> {
538 : public:
539 : template<class A> struct Dont_Instantiate_nsTArray_of;
540 : template<class A> struct Instead_Use_nsTArray_of;
541 :
542 : static Dont_Instantiate_nsTArray_of<nsTAutoString_CharT> *
543 : Construct(Instead_Use_nsTArray_of<nsTString_CharT> *e) {
544 : return 0;
545 : }
546 : template<class A>
547 : static Dont_Instantiate_nsTArray_of<nsTAutoString_CharT> *
548 : Construct(Instead_Use_nsTArray_of<nsTString_CharT> *e,
549 : const A &arg) {
550 : return 0;
551 : }
552 : static Dont_Instantiate_nsTArray_of<nsTAutoString_CharT> *
553 : Destruct(Instead_Use_nsTArray_of<nsTString_CharT> *e) {
554 : return 0;
555 : }
556 : };
557 :
558 : /**
559 : * nsTXPIDLString extends nsTString such that:
560 : *
561 : * (1) mData can be null
562 : * (2) objects of this type can be automatically cast to |const CharT*|
563 : * (3) getter_Copies method is supported to adopt data allocated with
564 : * NS_Alloc, such as "out string" parameters in XPIDL.
565 : *
566 : * NAMES:
567 : * nsXPIDLString for wide characters
568 : * nsXPIDLCString for narrow characters
569 : */
570 : class nsTXPIDLString_CharT : public nsTString_CharT
571 431754 : {
572 : public:
573 :
574 : typedef nsTXPIDLString_CharT self_type;
575 :
576 : public:
577 :
578 433215 : nsTXPIDLString_CharT()
579 433215 : : string_type(char_traits::sEmptyBuffer, 0, F_TERMINATED | F_VOIDED) {}
580 :
581 : // copy-constructor required to avoid default
582 : nsTXPIDLString_CharT( const self_type& str )
583 : : string_type(char_traits::sEmptyBuffer, 0, F_TERMINATED | F_VOIDED)
584 : {
585 : Assign(str);
586 : }
587 :
588 : // return nsnull if we are voided
589 375754 : const char_type* get() const
590 : {
591 375754 : return (mFlags & F_VOIDED) ? nsnull : mData;
592 : }
593 :
594 : // this case operator is the reason why this class cannot just be a
595 : // typedef for nsTString
596 366702 : operator const char_type*() const
597 : {
598 366702 : return get();
599 : }
600 :
601 : // need this to diambiguous operator[int]
602 : char_type operator[]( PRInt32 i ) const
603 : {
604 : return CharAt(index_type(i));
605 : }
606 :
607 : // |operator=| does not inherit, so we must define our own
608 : self_type& operator=( char_type c ) { Assign(c); return *this; }
609 4 : self_type& operator=( const char_type* data ) { Assign(data); return *this; }
610 0 : self_type& operator=( const self_type& str ) { Assign(str); return *this; }
611 3498 : self_type& operator=( const substring_type& str ) { Assign(str); return *this; }
612 : self_type& operator=( const substring_tuple_type& tuple ) { Assign(tuple); return *this; }
613 : };
614 :
615 :
616 : /**
617 : * getter_Copies support for use with raw string out params:
618 : *
619 : * NS_IMETHOD GetBlah(char**);
620 : *
621 : * void some_function()
622 : * {
623 : * nsXPIDLCString blah;
624 : * GetBlah(getter_Copies(blah));
625 : * // ...
626 : * }
627 : */
628 : class NS_STACK_CLASS nsTGetterCopies_CharT
629 : {
630 : public:
631 : typedef CharT char_type;
632 :
633 125207 : nsTGetterCopies_CharT(nsTSubstring_CharT& str)
634 125207 : : mString(str), mData(nsnull) {}
635 :
636 125207 : ~nsTGetterCopies_CharT()
637 : {
638 125207 : mString.Adopt(mData); // OK if mData is null
639 125207 : }
640 :
641 125207 : operator char_type**()
642 : {
643 125207 : return &mData;
644 : }
645 :
646 : private:
647 : nsTSubstring_CharT& mString;
648 : char_type* mData;
649 : };
650 :
651 : inline
652 : nsTGetterCopies_CharT
653 125207 : getter_Copies( nsTSubstring_CharT& aString )
654 : {
655 125207 : return nsTGetterCopies_CharT(aString);
656 : }
657 :
658 :
659 : /**
660 : * nsTAdoptingString extends nsTXPIDLString such that:
661 : *
662 : * (1) Adopt given string on construction or assignment, i.e. take
663 : * the value of what's given, and make what's given forget its
664 : * value. Note that this class violates constness in a few
665 : * places. Be careful!
666 : */
667 : class nsTAdoptingString_CharT : public nsTXPIDLString_CharT
668 5945 : {
669 : public:
670 :
671 : typedef nsTAdoptingString_CharT self_type;
672 :
673 : public:
674 :
675 7391 : explicit nsTAdoptingString_CharT() {}
676 0 : explicit nsTAdoptingString_CharT(char_type* str, size_type length = size_type(-1))
677 0 : {
678 0 : Adopt(str, length);
679 0 : }
680 :
681 : // copy-constructor required to adopt on copy. Note that this
682 : // will violate the constness of |str| in the operator=()
683 : // call. |str| will be truncated as a side-effect of this
684 : // constructor.
685 : nsTAdoptingString_CharT( const self_type& str )
686 : {
687 : *this = str;
688 : }
689 :
690 : // |operator=| does not inherit, so we must define our own
691 : self_type& operator=( const substring_type& str ) { Assign(str); return *this; }
692 : self_type& operator=( const substring_tuple_type& tuple ) { Assign(tuple); return *this; }
693 :
694 : // Adopt(), if possible, when assigning to a self_type&. Note
695 : // that this violates the constness of str, str is always
696 : // truncated when this operator is called.
697 : self_type& operator=( const self_type& str );
698 :
699 : private:
700 : self_type& operator=( const char_type* data ) MOZ_DELETE;
701 : self_type& operator=( char_type* data ) MOZ_DELETE;
702 : };
703 :
|