VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/xpcom/string/public/nsStringAPI.h@ 78394

Last change on this file since 78394 was 11551, checked in by vboxsync, 16 years ago

API/xpcom: prefix any C symbols in VBoxXPCOM.so, to avoid namespace pollution. Enabled only on Linux at the moment.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 30.4 KB
Line 
1/* vim:set ts=2 sw=2 et cindent: */
2/* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is Mozilla.
16 *
17 * The Initial Developer of the Original Code is IBM Corporation.
18 * Portions created by IBM Corporation are Copyright (C) 2003
19 * IBM Corporation. All Rights Reserved.
20 *
21 * Contributor(s):
22 * Darin Fisher <[email protected]>
23 *
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
35 *
36 * ***** END LICENSE BLOCK ***** */
37
38#ifndef nsStringAPI_h__
39#define nsStringAPI_h__
40
41/**
42 * nsStringAPI.h
43 *
44 * This file describes a minimal API for working with XPCOM's abstract
45 * string classes. It divorces the consumer from having any run-time
46 * dependency on the implementation details of the abstract string types.
47 */
48
49#include "nscore.h"
50
51#ifdef VBOX_WITH_XPCOM_NAMESPACE_CLEANUP
52#define NS_CStringContainerInit VBoxNsxpNS_CStringContainerInit
53#define NS_CStringContainerFinish VBoxNsxpNS_CStringContainerFinish
54#define NS_CStringCloneData VBoxNsxpNS_CStringCloneData
55#define NS_CStringCopy VBoxNsxpNS_CStringCopy
56#define NS_CStringGetData VBoxNsxpNS_CStringGetData
57#define NS_CStringSetData VBoxNsxpNS_CStringSetData
58#define NS_CStringSetDataRange VBoxNsxpNS_CStringSetDataRange
59#define NS_UTF16ToCString VBoxNsxpNS_UTF16ToCString
60#define NS_CStringToUTF16 VBoxNsxpNS_CStringToUTF16
61#define NS_StringContainerInit VBoxNsxpNS_StringContainerInit
62#define NS_StringContainerFinish VBoxNsxpNS_StringContainerFinish
63#define NS_StringCloneData VBoxNsxpNS_StringCloneData
64#define NS_StringCopy VBoxNsxpNS_StringCopy
65#define NS_StringGetData VBoxNsxpNS_StringGetData
66#define NS_StringSetData VBoxNsxpNS_StringSetData
67#define NS_StringSetDataRange VBoxNsxpNS_StringSetDataRange
68#endif /* VBOX_WITH_XPCOM_NAMESPACE_CLEANUP */
69
70#define NS_STRINGAPI(x) extern "C" NS_COM x
71
72/* The base string types */
73class nsAString;
74class nsACString;
75
76/* ------------------------------------------------------------------------- */
77
78/**
79 * nsStringContainer
80 *
81 * This is an opaque data type that is large enough to hold the canonical
82 * implementation of nsAString. The binary structure of this class is an
83 * implementation detail.
84 *
85 * The string data stored in a string container is always single fragment
86 * and null-terminated.
87 *
88 * Typically, string containers are allocated on the stack for temporary
89 * use. However, they can also be malloc'd if necessary. In either case,
90 * a string container is not useful until it has been initialized with a
91 * call to NS_StringContainerInit. The following example shows how to use
92 * a string container to call a function that takes a |nsAString &| out-param.
93 *
94 * NS_METHOD GetBlah(nsAString &aBlah);
95 *
96 * nsresult MyCode()
97 * {
98 * nsresult rv;
99 *
100 * nsStringContainer sc;
101 * rv = NS_StringContainerInit(sc);
102 * if (NS_FAILED(rv))
103 * return rv;
104 *
105 * rv = GetBlah(sc);
106 * if (NS_SUCCEEDED(rv))
107 * {
108 * const PRUnichar *data;
109 * NS_StringGetData(sc, &data);
110 * //
111 * // |data| now points to the result of the GetBlah function
112 * //
113 * }
114 *
115 * NS_StringContainerFinish(sc);
116 * return rv;
117 * }
118 *
119 * The following example show how to use a string container to pass a string
120 * parameter to a function taking a |const nsAString &| in-param.
121 *
122 * NS_METHOD SetBlah(const nsAString &aBlah);
123 *
124 * nsresult MyCode()
125 * {
126 * nsresult rv;
127 *
128 * nsStringContainer sc;
129 * rv = NS_StringContainerInit(sc);
130 * if (NS_FAILED(rv))
131 * return rv;
132 *
133 * const PRUnichar kData[] = {'x','y','z','\0'};
134 * rv = NS_StringSetData(sc, kData, sizeof(kData)/2 - 1);
135 * if (NS_SUCCEEDED(rv))
136 * rv = SetBlah(sc);
137 *
138 * NS_StringContainerFinish(sc);
139 * return rv;
140 * }
141 */
142class nsStringContainer;
143
144/**
145 * NS_StringContainerInit
146 *
147 * @param aContainer string container reference
148 * @return NS_OK if string container successfully initialized
149 *
150 * This function may allocate additional memory for aContainer. When
151 * aContainer is no longer needed, NS_StringContainerFinish should be called.
152 *
153 * @status FROZEN
154 */
155NS_STRINGAPI(nsresult)
156NS_StringContainerInit(nsStringContainer &aContainer);
157
158/**
159 * NS_StringContainerFinish
160 *
161 * @param aContainer string container reference
162 *
163 * This function frees any memory owned by aContainer.
164 *
165 * @status FROZEN
166 */
167NS_STRINGAPI(void)
168NS_StringContainerFinish(nsStringContainer &aContainer);
169
170/* ------------------------------------------------------------------------- */
171
172/**
173 * NS_StringGetData
174 *
175 * This function returns a const character pointer to the string's internal
176 * buffer, the length of the string, and a boolean value indicating whether
177 * or not the buffer is null-terminated.
178 *
179 * @param aStr abstract string reference
180 * @param aData out param that will hold the address of aStr's
181 * internal buffer
182 * @param aTerminated if non-null, this out param will be set to indicate
183 * whether or not aStr's internal buffer is null-
184 * terminated
185 * @return length of aStr's internal buffer
186 *
187 * @status FROZEN
188 */
189NS_STRINGAPI(PRUint32)
190NS_StringGetData
191 (const nsAString &aStr, const PRUnichar **aData,
192 PRBool *aTerminated = nsnull);
193
194/**
195 * NS_StringCloneData
196 *
197 * This function returns a null-terminated copy of the string's
198 * internal buffer.
199 *
200 * @param aStr abstract string reference
201 * @return null-terminated copy of the string's internal buffer
202 * (it must be free'd using using nsMemory::Free)
203 *
204 * @status FROZEN
205 */
206NS_STRINGAPI(PRUnichar *)
207NS_StringCloneData
208 (const nsAString &aStr);
209
210/**
211 * NS_StringSetData
212 *
213 * This function copies aData into aStr.
214 *
215 * @param aStr abstract string reference
216 * @param aData character buffer
217 * @param aDataLength number of characters to copy from source string (pass
218 * PR_UINT32_MAX to copy until end of aData, designated by
219 * a null character)
220 * @return NS_OK if function succeeded
221 *
222 * This function does not necessarily null-terminate aStr after copying data
223 * from aData. The behavior depends on the implementation of the abstract
224 * string, aStr. If aStr is a reference to a nsStringContainer, then its data
225 * will be null-terminated by this function.
226 *
227 * @status FROZEN
228 */
229NS_STRINGAPI(nsresult)
230NS_StringSetData
231 (nsAString &aStr, const PRUnichar *aData,
232 PRUint32 aDataLength = PR_UINT32_MAX);
233
234/**
235 * NS_StringSetDataRange
236 *
237 * This function copies aData into a section of aStr. As a result it can be
238 * used to insert new characters into the string.
239 *
240 * @param aStr abstract string reference
241 * @param aCutOffset starting index where the string's existing data
242 * is to be overwritten (pass PR_UINT32_MAX to cause
243 * aData to be appended to the end of aStr, in which
244 * case the value of aCutLength is ignored).
245 * @param aCutLength number of characters to overwrite starting at
246 * aCutOffset (pass PR_UINT32_MAX to overwrite until the
247 * end of aStr).
248 * @param aData character buffer (pass null to cause this function
249 * to simply remove the "cut" range)
250 * @param aDataLength number of characters to copy from source string (pass
251 * PR_UINT32_MAX to copy until end of aData, designated by
252 * a null character)
253 * @return NS_OK if function succeeded
254 *
255 * This function does not necessarily null-terminate aStr after copying data
256 * from aData. The behavior depends on the implementation of the abstract
257 * string, aStr. If aStr is a reference to a nsStringContainer, then its data
258 * will be null-terminated by this function.
259 *
260 * @status FROZEN
261 */
262NS_STRINGAPI(nsresult)
263NS_StringSetDataRange
264 (nsAString &aStr, PRUint32 aCutOffset, PRUint32 aCutLength,
265 const PRUnichar *aData, PRUint32 aDataLength = PR_UINT32_MAX);
266
267/**
268 * NS_StringCopy
269 *
270 * This function makes aDestStr have the same value as aSrcStr. It is
271 * provided as an optimization.
272 *
273 * @param aDestStr abstract string reference to be modified
274 * @param aSrcStr abstract string reference containing source string
275 * @return NS_OK if function succeeded
276 *
277 * This function does not necessarily null-terminate aDestStr after copying
278 * data from aSrcStr. The behavior depends on the implementation of the
279 * abstract string, aDestStr. If aDestStr is a reference to a
280 * nsStringContainer, then its data will be null-terminated by this function.
281 *
282 * @status FROZEN
283 */
284NS_STRINGAPI(nsresult)
285NS_StringCopy
286 (nsAString &aDestStr, const nsAString &aSrcStr);
287
288/**
289 * NS_StringAppendData
290 *
291 * This function appends data to the existing value of aStr.
292 *
293 * @param aStr abstract string reference to be modified
294 * @param aData character buffer
295 * @param aDataLength number of characters to append (pass PR_UINT32_MAX to
296 * append until a null-character is encountered)
297 * @return NS_OK if function succeeded
298 *
299 * This function does not necessarily null-terminate aStr upon completion.
300 * The behavior depends on the implementation of the abstract string, aStr.
301 * If aStr is a reference to a nsStringContainer, then its data will be null-
302 * terminated by this function.
303 */
304inline NS_HIDDEN_(nsresult)
305NS_StringAppendData(nsAString &aStr, const PRUnichar *aData,
306 PRUint32 aDataLength = PR_UINT32_MAX)
307{
308 return NS_StringSetDataRange(aStr, PR_UINT32_MAX, 0, aData, aDataLength);
309}
310
311/**
312 * NS_StringInsertData
313 *
314 * This function inserts data into the existing value of aStr at the specified
315 * offset.
316 *
317 * @param aStr abstract string reference to be modified
318 * @param aOffset specifies where in the string to insert aData
319 * @param aData character buffer
320 * @param aDataLength number of characters to append (pass PR_UINT32_MAX to
321 * append until a null-character is encountered)
322 * @return NS_OK if function succeeded
323 *
324 * This function does not necessarily null-terminate aStr upon completion.
325 * The behavior depends on the implementation of the abstract string, aStr.
326 * If aStr is a reference to a nsStringContainer, then its data will be null-
327 * terminated by this function.
328 */
329inline NS_HIDDEN_(nsresult)
330NS_StringInsertData(nsAString &aStr, PRUint32 aOffset, const PRUnichar *aData,
331 PRUint32 aDataLength = PR_UINT32_MAX)
332{
333 return NS_StringSetDataRange(aStr, aOffset, 0, aData, aDataLength);
334}
335
336/**
337 * NS_StringCutData
338 *
339 * This function shortens the existing value of aStr, by removing characters
340 * at the specified offset.
341 *
342 * @param aStr abstract string reference to be modified
343 * @param aCutOffset specifies where in the string to insert aData
344 * @param aCutLength number of characters to remove
345 * @return NS_OK if function succeeded
346 */
347inline NS_HIDDEN_(nsresult)
348NS_StringCutData(nsAString &aStr, PRUint32 aCutOffset, PRUint32 aCutLength)
349{
350 return NS_StringSetDataRange(aStr, aCutOffset, aCutLength, nsnull, 0);
351}
352
353/* ------------------------------------------------------------------------- */
354
355/**
356 * nsCStringContainer
357 *
358 * This is an opaque data type that is large enough to hold the canonical
359 * implementation of nsACString. The binary structure of this class is an
360 * implementation detail.
361 *
362 * The string data stored in a string container is always single fragment
363 * and null-terminated.
364 *
365 * @see nsStringContainer for use cases and further documentation.
366 */
367class nsCStringContainer;
368
369/**
370 * NS_CStringContainerInit
371 *
372 * @param aContainer string container reference
373 * @return NS_OK if string container successfully initialized
374 *
375 * This function may allocate additional memory for aContainer. When
376 * aContainer is no longer needed, NS_CStringContainerFinish should be called.
377 *
378 * @status FROZEN
379 */
380NS_STRINGAPI(nsresult)
381NS_CStringContainerInit(nsCStringContainer &aContainer);
382
383/**
384 * NS_CStringContainerFinish
385 *
386 * @param aContainer string container reference
387 *
388 * This function frees any memory owned by aContainer.
389 *
390 * @status FROZEN
391 */
392NS_STRINGAPI(void)
393NS_CStringContainerFinish(nsCStringContainer &aContainer);
394
395/* ------------------------------------------------------------------------- */
396
397/**
398 * NS_CStringGetData
399 *
400 * This function returns a const character pointer to the string's internal
401 * buffer, the length of the string, and a boolean value indicating whether
402 * or not the buffer is null-terminated.
403 *
404 * @param aStr abstract string reference
405 * @param aData out param that will hold the address of aStr's
406 * internal buffer
407 * @param aTerminated if non-null, this out param will be set to indicate
408 * whether or not aStr's internal buffer is null-
409 * terminated
410 * @return length of aStr's internal buffer
411 *
412 * @status FROZEN
413 */
414NS_STRINGAPI(PRUint32)
415NS_CStringGetData
416 (const nsACString &aStr, const char **aData,
417 PRBool *aTerminated = nsnull);
418
419/**
420 * NS_CStringCloneData
421 *
422 * This function returns a null-terminated copy of the string's
423 * internal buffer.
424 *
425 * @param aStr abstract string reference
426 * @return null-terminated copy of the string's internal buffer
427 * (it must be free'd using using nsMemory::Free)
428 *
429 * @status FROZEN
430 */
431NS_STRINGAPI(char *)
432NS_CStringCloneData
433 (const nsACString &aStr);
434
435/**
436 * NS_CStringSetData
437 *
438 * This function copies aData into aStr.
439 *
440 * @param aStr abstract string reference
441 * @param aData character buffer
442 * @param aDataLength number of characters to copy from source string (pass
443 * PR_UINT32_MAX to copy until end of aData, designated by
444 * a null character)
445 * @return NS_OK if function succeeded
446 *
447 * This function does not necessarily null-terminate aStr after copying data
448 * from aData. The behavior depends on the implementation of the abstract
449 * string, aStr. If aStr is a reference to a nsStringContainer, then its data
450 * will be null-terminated by this function.
451 *
452 * @status FROZEN
453 */
454NS_STRINGAPI(nsresult)
455NS_CStringSetData
456 (nsACString &aStr, const char *aData,
457 PRUint32 aDataLength = PR_UINT32_MAX);
458
459/**
460 * NS_CStringSetDataRange
461 *
462 * This function copies aData into a section of aStr. As a result it can be
463 * used to insert new characters into the string.
464 *
465 * @param aStr abstract string reference
466 * @param aCutOffset starting index where the string's existing data
467 * is to be overwritten (pass PR_UINT32_MAX to cause
468 * aData to be appended to the end of aStr, in which
469 * case the value of aCutLength is ignored).
470 * @param aCutLength number of characters to overwrite starting at
471 * aCutOffset (pass PR_UINT32_MAX to overwrite until the
472 * end of aStr).
473 * @param aData character buffer (pass null to cause this function
474 * to simply remove the "cut" range)
475 * @param aDataLength number of characters to copy from source string (pass
476 * PR_UINT32_MAX to copy until end of aData, designated by
477 * a null character)
478 * @return NS_OK if function succeeded
479 *
480 * This function does not necessarily null-terminate aStr after copying data
481 * from aData. The behavior depends on the implementation of the abstract
482 * string, aStr. If aStr is a reference to a nsStringContainer, then its data
483 * will be null-terminated by this function.
484 *
485 * @status FROZEN
486 */
487NS_STRINGAPI(nsresult)
488NS_CStringSetDataRange
489 (nsACString &aStr, PRUint32 aCutOffset, PRUint32 aCutLength,
490 const char *aData, PRUint32 aDataLength = PR_UINT32_MAX);
491
492/**
493 * NS_CStringCopy
494 *
495 * This function makes aDestStr have the same value as aSrcStr. It is
496 * provided as an optimization.
497 *
498 * @param aDestStr abstract string reference to be modified
499 * @param aSrcStr abstract string reference containing source string
500 * @return NS_OK if function succeeded
501 *
502 * This function does not necessarily null-terminate aDestStr after copying
503 * data from aSrcStr. The behavior depends on the implementation of the
504 * abstract string, aDestStr. If aDestStr is a reference to a
505 * nsStringContainer, then its data will be null-terminated by this function.
506 *
507 * @status FROZEN
508 */
509NS_STRINGAPI(nsresult)
510NS_CStringCopy
511 (nsACString &aDestStr, const nsACString &aSrcStr);
512
513/**
514 * NS_CStringAppendData
515 *
516 * This function appends data to the existing value of aStr.
517 *
518 * @param aStr abstract string reference to be modified
519 * @param aData character buffer
520 * @param aDataLength number of characters to append (pass PR_UINT32_MAX to
521 * append until a null-character is encountered)
522 * @return NS_OK if function succeeded
523 *
524 * This function does not necessarily null-terminate aStr upon completion.
525 * The behavior depends on the implementation of the abstract string, aStr.
526 * If aStr is a reference to a nsStringContainer, then its data will be null-
527 * terminated by this function.
528 */
529inline NS_HIDDEN_(nsresult)
530NS_CStringAppendData(nsACString &aStr, const char *aData,
531 PRUint32 aDataLength = PR_UINT32_MAX)
532{
533 return NS_CStringSetDataRange(aStr, PR_UINT32_MAX, 0, aData, aDataLength);
534}
535
536/**
537 * NS_CStringInsertData
538 *
539 * This function inserts data into the existing value of aStr at the specified
540 * offset.
541 *
542 * @param aStr abstract string reference to be modified
543 * @param aOffset specifies where in the string to insert aData
544 * @param aData character buffer
545 * @param aDataLength number of characters to append (pass PR_UINT32_MAX to
546 * append until a null-character is encountered)
547 * @return NS_OK if function succeeded
548 *
549 * This function does not necessarily null-terminate aStr upon completion.
550 * The behavior depends on the implementation of the abstract string, aStr.
551 * If aStr is a reference to a nsStringContainer, then its data will be null-
552 * terminated by this function.
553 */
554inline NS_HIDDEN_(nsresult)
555NS_CStringInsertData(nsACString &aStr, PRUint32 aOffset, const char *aData,
556 PRUint32 aDataLength = PR_UINT32_MAX)
557{
558 return NS_CStringSetDataRange(aStr, aOffset, 0, aData, aDataLength);
559}
560
561/**
562 * NS_CStringCutData
563 *
564 * This function shortens the existing value of aStr, by removing characters
565 * at the specified offset.
566 *
567 * @param aStr abstract string reference to be modified
568 * @param aCutOffset specifies where in the string to insert aData
569 * @param aCutLength number of characters to remove
570 * @return NS_OK if function succeeded
571 */
572inline NS_HIDDEN_(nsresult)
573NS_CStringCutData(nsACString &aStr, PRUint32 aCutOffset, PRUint32 aCutLength)
574{
575 return NS_CStringSetDataRange(aStr, aCutOffset, aCutLength, nsnull, 0);
576}
577
578/* ------------------------------------------------------------------------- */
579
580/**
581 * Encodings that can be used with the following conversion routines.
582 */
583enum nsCStringEncoding {
584 /* Conversion between ASCII and UTF-16 assumes that all bytes in the source
585 * string are 7-bit ASCII and can be inflated to UTF-16 by inserting null
586 * bytes. Reverse conversion is done by truncating every other byte. The
587 * conversion may result in loss and/or corruption of information if the
588 * strings do not strictly contain ASCII data. */
589 NS_CSTRING_ENCODING_ASCII = 0,
590
591 /* Conversion between UTF-8 and UTF-16 is non-lossy. */
592 NS_CSTRING_ENCODING_UTF8 = 1,
593
594 /* Conversion from UTF-16 to the native filesystem charset may result in a
595 * loss of information. No attempt is made to protect against data loss in
596 * this case. The native filesystem charset applies to strings passed to
597 * the "Native" method variants on nsIFile and nsILocalFile. */
598 NS_CSTRING_ENCODING_NATIVE_FILESYSTEM = 2
599};
600
601/**
602 * NS_CStringToUTF16
603 *
604 * This function converts the characters in a nsACString to an array of UTF-16
605 * characters, in the platform endianness. The result is stored in a nsAString
606 * object.
607 *
608 * @param aSource abstract string reference containing source string
609 * @param aSrcEncoding character encoding of the source string
610 * @param aDest abstract string reference to hold the result
611 *
612 * @status FROZEN
613 */
614NS_STRINGAPI(nsresult)
615NS_CStringToUTF16(const nsACString &aSource, nsCStringEncoding aSrcEncoding,
616 nsAString &aDest);
617
618/**
619 * NS_UTF16ToCString
620 *
621 * This function converts the UTF-16 characters in a nsAString to a single-byte
622 * encoding. The result is stored in a nsACString object. In some cases this
623 * conversion may be lossy. In such cases, the conversion may succeed with a
624 * return code indicating loss of information. The exact behavior is not
625 * specified at this time.
626 *
627 * @param aSource abstract string reference containing source string
628 * @param aDestEncoding character encoding of the resulting string
629 * @param aDest abstract string reference to hold the result
630 *
631 * @status FROZEN
632 */
633NS_STRINGAPI(nsresult)
634NS_UTF16ToCString(const nsAString &aSource, nsCStringEncoding aDestEncoding,
635 nsACString &aDest);
636
637/* ------------------------------------------------------------------------- */
638
639/**
640 * Below we define nsAString and nsACString. The "_external" suffix is an
641 * implementation detail. nsAString_external is the name of the external
642 * representation of nsAString from the point of view of the Mozilla codebase.
643 * To a user of this API, nsAString_external is exactly nsAString.
644 *
645 * These classes should be treated as abstract classes with unspecified
646 * structure. The inline methods are provided as helper functions around the
647 * C-style API provided above.
648 *
649 * Do not try to mix these definitions of nsAString and nsACString with the
650 * internal definition of these classes from nsAString.h in the Mozilla tree.
651 */
652
653#ifndef NS_STRINGAPI_IMPL
654#define nsAString_external nsAString
655#define nsACString_external nsACString
656#endif
657
658class nsAString_external
659{
660#ifndef NS_STRINGAPI_IMPL
661
662public:
663 typedef PRUnichar char_type;
664 typedef nsAString_external self_type;
665 typedef PRUint32 size_type;
666 typedef PRUint32 index_type;
667
668 NS_HIDDEN_(const char_type*) BeginReading() const
669 {
670 const char_type *data;
671 NS_StringGetData(*this, &data);
672 return data;
673 }
674
675 NS_HIDDEN_(const char_type*) EndReading() const
676 {
677 const char_type *data;
678 PRUint32 len = NS_StringGetData(*this, &data);
679 return data + len;
680 }
681
682 NS_HIDDEN_(size_type) Length() const
683 {
684 const char_type* data;
685 return NS_StringGetData(*this, &data);
686 }
687
688 NS_HIDDEN_(void) Assign(const self_type& aString)
689 {
690 NS_StringCopy(*this, aString);
691 }
692 NS_HIDDEN_(void) Assign(const char_type* aData, size_type aLength = PR_UINT32_MAX)
693 {
694 NS_StringSetData(*this, aData, aLength);
695 }
696 NS_HIDDEN_(void) Assign(char_type aChar)
697 {
698 NS_StringSetData(*this, &aChar, 1);
699 }
700
701 NS_HIDDEN_(self_type&) operator=(const self_type& aString) { Assign(aString); return *this; }
702 NS_HIDDEN_(self_type&) operator=(const char_type* aPtr) { Assign(aPtr); return *this; }
703 NS_HIDDEN_(self_type&) operator=(char_type aChar) { Assign(aChar); return *this; }
704
705 NS_HIDDEN_(void) Replace( index_type cutStart, size_type cutLength, const char_type* data, size_type length = size_type(-1) )
706 {
707 NS_StringSetDataRange(*this, cutStart, cutLength, data, length);
708 }
709 NS_HIDDEN_(void) Replace( index_type cutStart, size_type cutLength, char_type c )
710 {
711 Replace(cutStart, cutLength, &c, 1);
712 }
713 NS_HIDDEN_(void) Replace( index_type cutStart, size_type cutLength, const self_type& readable )
714 {
715 const char_type* data;
716 PRUint32 dataLen = NS_StringGetData(readable, &data);
717 NS_StringSetDataRange(*this, cutStart, cutLength, data, dataLen);
718 }
719
720 NS_HIDDEN_(void) Append( char_type c ) { Replace(size_type(-1), 0, c); }
721 NS_HIDDEN_(void) Append( const char_type* data, size_type length = size_type(-1) ) { Replace(size_type(-1), 0, data, length); }
722 NS_HIDDEN_(void) Append( const self_type& readable ) { Replace(size_type(-1), 0, readable); }
723
724 NS_HIDDEN_(self_type&) operator+=( char_type c ) { Append(c); return *this; }
725 NS_HIDDEN_(self_type&) operator+=( const char_type* data ) { Append(data); return *this; }
726 NS_HIDDEN_(self_type&) operator+=( const self_type& readable ) { Append(readable); return *this; }
727
728 NS_HIDDEN_(void) Insert( char_type c, index_type pos ) { Replace(pos, 0, c); }
729 NS_HIDDEN_(void) Insert( const char_type* data, index_type pos, size_type length = size_type(-1) ) { Replace(pos, 0, data, length); }
730 NS_HIDDEN_(void) Insert( const self_type& readable, index_type pos ) { Replace(pos, 0, readable); }
731
732 NS_HIDDEN_(void) Cut( index_type cutStart, size_type cutLength ) { Replace(cutStart, cutLength, nsnull, 0); }
733
734#endif // NS_STRINGAPI_IMPL
735
736private:
737 void *v;
738};
739
740class nsACString_external
741{
742#ifndef NS_STRINGAPI_IMPL
743
744public:
745 typedef char char_type;
746 typedef nsACString_external self_type;
747 typedef PRUint32 size_type;
748 typedef PRUint32 index_type;
749
750 NS_HIDDEN_(const char_type*) BeginReading() const
751 {
752 const char_type *data;
753 NS_CStringGetData(*this, &data);
754 return data;
755 }
756
757 NS_HIDDEN_(const char_type*) EndReading() const
758 {
759 const char_type *data;
760 PRUint32 len = NS_CStringGetData(*this, &data);
761 return data + len;
762 }
763
764 NS_HIDDEN_(size_type) Length() const
765 {
766 const char_type* data;
767 return NS_CStringGetData(*this, &data);
768 }
769
770 NS_HIDDEN_(void) Assign(const self_type& aString)
771 {
772 NS_CStringCopy(*this, aString);
773 }
774 NS_HIDDEN_(void) Assign(const char_type* aData, size_type aLength = PR_UINT32_MAX)
775 {
776 NS_CStringSetData(*this, aData, aLength);
777 }
778 NS_HIDDEN_(void) Assign(char_type aChar)
779 {
780 NS_CStringSetData(*this, &aChar, 1);
781 }
782
783 NS_HIDDEN_(self_type&) operator=(const self_type& aString) { Assign(aString); return *this; }
784 NS_HIDDEN_(self_type&) operator=(const char_type* aPtr) { Assign(aPtr); return *this; }
785 NS_HIDDEN_(self_type&) operator=(char_type aChar) { Assign(aChar); return *this; }
786
787 NS_HIDDEN_(void) Replace( index_type cutStart, size_type cutLength, const char_type* data, size_type length = size_type(-1) )
788 {
789 NS_CStringSetDataRange(*this, cutStart, cutLength, data, length);
790 }
791 NS_HIDDEN_(void) Replace( index_type cutStart, size_type cutLength, char_type c )
792 {
793 Replace(cutStart, cutLength, &c, 1);
794 }
795 NS_HIDDEN_(void) Replace( index_type cutStart, size_type cutLength, const self_type& readable )
796 {
797 const char_type* data;
798 PRUint32 dataLen = NS_CStringGetData(readable, &data);
799 NS_CStringSetDataRange(*this, cutStart, cutLength, data, dataLen);
800 }
801
802 NS_HIDDEN_(void) Append( char_type c ) { Replace(size_type(-1), 0, c); }
803 NS_HIDDEN_(void) Append( const char_type* data, size_type length = size_type(-1) ) { Replace(size_type(-1), 0, data, length); }
804 NS_HIDDEN_(void) Append( const self_type& readable ) { Replace(size_type(-1), 0, readable); }
805
806 NS_HIDDEN_(self_type&) operator+=( char_type c ) { Append(c); return *this; }
807 NS_HIDDEN_(self_type&) operator+=( const char_type* data ) { Append(data); return *this; }
808 NS_HIDDEN_(self_type&) operator+=( const self_type& readable ) { Append(readable); return *this; }
809
810 NS_HIDDEN_(void) Insert( char_type c, index_type pos ) { Replace(pos, 0, c); }
811 NS_HIDDEN_(void) Insert( const char_type* data, index_type pos, size_type length = size_type(-1) ) { Replace(pos, 0, data, length); }
812 NS_HIDDEN_(void) Insert( const self_type& readable, index_type pos ) { Replace(pos, 0, readable); }
813
814 NS_HIDDEN_(void) Cut( index_type cutStart, size_type cutLength ) { Replace(cutStart, cutLength, nsnull, 0); }
815
816#endif // NS_STRINGAPI_IMPL
817
818private:
819 void *v;
820};
821
822/* ------------------------------------------------------------------------- */
823
824/**
825 * Below we define nsStringContainer and nsCStringContainer. These classes
826 * have unspecified structure. In most cases, your code should use
827 * nsEmbedString instead of these classes; however, if you prefer C-style
828 * programming, then look no further...
829 */
830
831class nsStringContainer : public nsAString_external
832{
833private:
834 void *d1;
835 PRUint32 d2;
836 void *d3;
837
838public:
839 nsStringContainer() {} // MSVC6 needs this
840};
841
842class nsCStringContainer : public nsACString_external
843{
844private:
845 void *d1;
846 PRUint32 d2;
847 void *d3;
848
849public:
850 nsCStringContainer() {} // MSVC6 needs this
851};
852
853#endif // nsStringAPI_h__
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette