VirtualBox

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

最後變更 在這個檔案是 101926,由 vboxsync 提交於 15 月 前

libs/xpcom: Remove some unused code, bugref:10545

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 30.0 KB
 
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
595/**
596 * NS_CStringToUTF16
597 *
598 * This function converts the characters in a nsACString to an array of UTF-16
599 * characters, in the platform endianness. The result is stored in a nsAString
600 * object.
601 *
602 * @param aSource abstract string reference containing source string
603 * @param aSrcEncoding character encoding of the source string
604 * @param aDest abstract string reference to hold the result
605 *
606 * @status FROZEN
607 */
608NS_STRINGAPI(nsresult)
609NS_CStringToUTF16(const nsACString &aSource, nsCStringEncoding aSrcEncoding,
610 nsAString &aDest);
611
612/**
613 * NS_UTF16ToCString
614 *
615 * This function converts the UTF-16 characters in a nsAString to a single-byte
616 * encoding. The result is stored in a nsACString object. In some cases this
617 * conversion may be lossy. In such cases, the conversion may succeed with a
618 * return code indicating loss of information. The exact behavior is not
619 * specified at this time.
620 *
621 * @param aSource abstract string reference containing source string
622 * @param aDestEncoding character encoding of the resulting string
623 * @param aDest abstract string reference to hold the result
624 *
625 * @status FROZEN
626 */
627NS_STRINGAPI(nsresult)
628NS_UTF16ToCString(const nsAString &aSource, nsCStringEncoding aDestEncoding,
629 nsACString &aDest);
630
631/* ------------------------------------------------------------------------- */
632
633/**
634 * Below we define nsAString and nsACString. The "_external" suffix is an
635 * implementation detail. nsAString_external is the name of the external
636 * representation of nsAString from the point of view of the Mozilla codebase.
637 * To a user of this API, nsAString_external is exactly nsAString.
638 *
639 * These classes should be treated as abstract classes with unspecified
640 * structure. The inline methods are provided as helper functions around the
641 * C-style API provided above.
642 *
643 * Do not try to mix these definitions of nsAString and nsACString with the
644 * internal definition of these classes from nsAString.h in the Mozilla tree.
645 */
646
647#ifndef NS_STRINGAPI_IMPL
648#define nsAString_external nsAString
649#define nsACString_external nsACString
650#endif
651
652class nsAString_external
653{
654#ifndef NS_STRINGAPI_IMPL
655
656public:
657 typedef PRUnichar char_type;
658 typedef nsAString_external self_type;
659 typedef PRUint32 size_type;
660 typedef PRUint32 index_type;
661
662 NS_HIDDEN_(const char_type*) BeginReading() const
663 {
664 const char_type *data;
665 NS_StringGetData(*this, &data);
666 return data;
667 }
668
669 NS_HIDDEN_(const char_type*) EndReading() const
670 {
671 const char_type *data;
672 PRUint32 len = NS_StringGetData(*this, &data);
673 return data + len;
674 }
675
676 NS_HIDDEN_(size_type) Length() const
677 {
678 const char_type* data;
679 return NS_StringGetData(*this, &data);
680 }
681
682 NS_HIDDEN_(void) Assign(const self_type& aString)
683 {
684 NS_StringCopy(*this, aString);
685 }
686 NS_HIDDEN_(void) Assign(const char_type* aData, size_type aLength = PR_UINT32_MAX)
687 {
688 NS_StringSetData(*this, aData, aLength);
689 }
690 NS_HIDDEN_(void) Assign(char_type aChar)
691 {
692 NS_StringSetData(*this, &aChar, 1);
693 }
694
695 NS_HIDDEN_(self_type&) operator=(const self_type& aString) { Assign(aString); return *this; }
696 NS_HIDDEN_(self_type&) operator=(const char_type* aPtr) { Assign(aPtr); return *this; }
697 NS_HIDDEN_(self_type&) operator=(char_type aChar) { Assign(aChar); return *this; }
698
699 NS_HIDDEN_(void) Replace( index_type cutStart, size_type cutLength, const char_type* data, size_type length = size_type(-1) )
700 {
701 NS_StringSetDataRange(*this, cutStart, cutLength, data, length);
702 }
703 NS_HIDDEN_(void) Replace( index_type cutStart, size_type cutLength, char_type c )
704 {
705 Replace(cutStart, cutLength, &c, 1);
706 }
707 NS_HIDDEN_(void) Replace( index_type cutStart, size_type cutLength, const self_type& readable )
708 {
709 const char_type* data;
710 PRUint32 dataLen = NS_StringGetData(readable, &data);
711 NS_StringSetDataRange(*this, cutStart, cutLength, data, dataLen);
712 }
713
714 NS_HIDDEN_(void) Append( char_type c ) { Replace(size_type(-1), 0, c); }
715 NS_HIDDEN_(void) Append( const char_type* data, size_type length = size_type(-1) ) { Replace(size_type(-1), 0, data, length); }
716 NS_HIDDEN_(void) Append( const self_type& readable ) { Replace(size_type(-1), 0, readable); }
717
718 NS_HIDDEN_(self_type&) operator+=( char_type c ) { Append(c); return *this; }
719 NS_HIDDEN_(self_type&) operator+=( const char_type* data ) { Append(data); return *this; }
720 NS_HIDDEN_(self_type&) operator+=( const self_type& readable ) { Append(readable); return *this; }
721
722 NS_HIDDEN_(void) Insert( char_type c, index_type pos ) { Replace(pos, 0, c); }
723 NS_HIDDEN_(void) Insert( const char_type* data, index_type pos, size_type length = size_type(-1) ) { Replace(pos, 0, data, length); }
724 NS_HIDDEN_(void) Insert( const self_type& readable, index_type pos ) { Replace(pos, 0, readable); }
725
726 NS_HIDDEN_(void) Cut( index_type cutStart, size_type cutLength ) { Replace(cutStart, cutLength, nsnull, 0); }
727
728#endif // NS_STRINGAPI_IMPL
729
730private:
731 void *v;
732};
733
734class nsACString_external
735{
736#ifndef NS_STRINGAPI_IMPL
737
738public:
739 typedef char char_type;
740 typedef nsACString_external self_type;
741 typedef PRUint32 size_type;
742 typedef PRUint32 index_type;
743
744 NS_HIDDEN_(const char_type*) BeginReading() const
745 {
746 const char_type *data;
747 NS_CStringGetData(*this, &data);
748 return data;
749 }
750
751 NS_HIDDEN_(const char_type*) EndReading() const
752 {
753 const char_type *data;
754 PRUint32 len = NS_CStringGetData(*this, &data);
755 return data + len;
756 }
757
758 NS_HIDDEN_(size_type) Length() const
759 {
760 const char_type* data;
761 return NS_CStringGetData(*this, &data);
762 }
763
764 NS_HIDDEN_(void) Assign(const self_type& aString)
765 {
766 NS_CStringCopy(*this, aString);
767 }
768 NS_HIDDEN_(void) Assign(const char_type* aData, size_type aLength = PR_UINT32_MAX)
769 {
770 NS_CStringSetData(*this, aData, aLength);
771 }
772 NS_HIDDEN_(void) Assign(char_type aChar)
773 {
774 NS_CStringSetData(*this, &aChar, 1);
775 }
776
777 NS_HIDDEN_(self_type&) operator=(const self_type& aString) { Assign(aString); return *this; }
778 NS_HIDDEN_(self_type&) operator=(const char_type* aPtr) { Assign(aPtr); return *this; }
779 NS_HIDDEN_(self_type&) operator=(char_type aChar) { Assign(aChar); return *this; }
780
781 NS_HIDDEN_(void) Replace( index_type cutStart, size_type cutLength, const char_type* data, size_type length = size_type(-1) )
782 {
783 NS_CStringSetDataRange(*this, cutStart, cutLength, data, length);
784 }
785 NS_HIDDEN_(void) Replace( index_type cutStart, size_type cutLength, char_type c )
786 {
787 Replace(cutStart, cutLength, &c, 1);
788 }
789 NS_HIDDEN_(void) Replace( index_type cutStart, size_type cutLength, const self_type& readable )
790 {
791 const char_type* data;
792 PRUint32 dataLen = NS_CStringGetData(readable, &data);
793 NS_CStringSetDataRange(*this, cutStart, cutLength, data, dataLen);
794 }
795
796 NS_HIDDEN_(void) Append( char_type c ) { Replace(size_type(-1), 0, c); }
797 NS_HIDDEN_(void) Append( const char_type* data, size_type length = size_type(-1) ) { Replace(size_type(-1), 0, data, length); }
798 NS_HIDDEN_(void) Append( const self_type& readable ) { Replace(size_type(-1), 0, readable); }
799
800 NS_HIDDEN_(self_type&) operator+=( char_type c ) { Append(c); return *this; }
801 NS_HIDDEN_(self_type&) operator+=( const char_type* data ) { Append(data); return *this; }
802 NS_HIDDEN_(self_type&) operator+=( const self_type& readable ) { Append(readable); return *this; }
803
804 NS_HIDDEN_(void) Insert( char_type c, index_type pos ) { Replace(pos, 0, c); }
805 NS_HIDDEN_(void) Insert( const char_type* data, index_type pos, size_type length = size_type(-1) ) { Replace(pos, 0, data, length); }
806 NS_HIDDEN_(void) Insert( const self_type& readable, index_type pos ) { Replace(pos, 0, readable); }
807
808 NS_HIDDEN_(void) Cut( index_type cutStart, size_type cutLength ) { Replace(cutStart, cutLength, nsnull, 0); }
809
810#endif // NS_STRINGAPI_IMPL
811
812private:
813 void *v;
814};
815
816/* ------------------------------------------------------------------------- */
817
818/**
819 * Below we define nsStringContainer and nsCStringContainer. These classes
820 * have unspecified structure. In most cases, your code should use
821 * nsEmbedString instead of these classes; however, if you prefer C-style
822 * programming, then look no further...
823 */
824
825class nsStringContainer : public nsAString_external
826{
827private:
828 void *d1;
829 PRUint32 d2;
830 void *d3;
831
832public:
833 nsStringContainer() {} // MSVC6 needs this
834};
835
836class nsCStringContainer : public nsACString_external
837{
838private:
839 void *d1;
840 PRUint32 d2;
841 void *d3;
842
843public:
844 nsCStringContainer() {} // MSVC6 needs this
845};
846
847#endif // nsStringAPI_h__
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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