1 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
---|
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 a small implementation of the nsAString and nsACString.
|
---|
16 | *
|
---|
17 | * The Initial Developer of the Original Code is
|
---|
18 | * Peter Annema <jaggernaut@netscape.com>.
|
---|
19 | *
|
---|
20 | * Portions created by the Initial Developer are Copyright (C) 2002
|
---|
21 | * the Initial Developer. All Rights Reserved.
|
---|
22 | *
|
---|
23 | * Contributor(s):
|
---|
24 | * Darin Fisher <darin@meer.net>
|
---|
25 | *
|
---|
26 | * Alternatively, the contents of this file may be used under the terms of
|
---|
27 | * either the GNU General Public License Version 2 or later (the "GPL"), or
|
---|
28 | * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
---|
29 | * in which case the provisions of the GPL or the LGPL are applicable instead
|
---|
30 | * of those above. If you wish to allow use of your version of this file only
|
---|
31 | * under the terms of either the GPL or the LGPL, and not to allow others to
|
---|
32 | * use your version of this file under the terms of the MPL, indicate your
|
---|
33 | * decision by deleting the provisions above and replace them with the notice
|
---|
34 | * and other provisions required by the GPL or the LGPL. If you do not delete
|
---|
35 | * the provisions above, a recipient may use your version of this file under
|
---|
36 | * the terms of any one of the MPL, the GPL or the LGPL.
|
---|
37 | *
|
---|
38 | * ***** END LICENSE BLOCK ***** */
|
---|
39 |
|
---|
40 | #ifndef nsEmbedString_h___
|
---|
41 | #define nsEmbedString_h___
|
---|
42 |
|
---|
43 | #include "nsStringAPI.h"
|
---|
44 |
|
---|
45 | class nsEmbedString : public nsStringContainer
|
---|
46 | {
|
---|
47 | public:
|
---|
48 | typedef nsEmbedString self_type;
|
---|
49 | typedef nsAString abstract_string_type;
|
---|
50 |
|
---|
51 | nsEmbedString()
|
---|
52 | {
|
---|
53 | NS_StringContainerInit(*this);
|
---|
54 | }
|
---|
55 |
|
---|
56 | nsEmbedString(const self_type& aString)
|
---|
57 | #ifdef VBOX
|
---|
58 | : nsStringContainer()
|
---|
59 | #endif
|
---|
60 | {
|
---|
61 | NS_StringContainerInit(*this);
|
---|
62 | NS_StringCopy(*this, aString);
|
---|
63 | }
|
---|
64 |
|
---|
65 | explicit
|
---|
66 | nsEmbedString(const abstract_string_type& aReadable)
|
---|
67 | {
|
---|
68 | NS_StringContainerInit(*this);
|
---|
69 | NS_StringCopy(*this, aReadable);
|
---|
70 | }
|
---|
71 |
|
---|
72 | explicit
|
---|
73 | nsEmbedString(const char_type* aData, size_type aLength = PR_UINT32_MAX)
|
---|
74 | {
|
---|
75 | NS_StringContainerInit(*this);
|
---|
76 | NS_StringSetData(*this, aData, aLength);
|
---|
77 | }
|
---|
78 |
|
---|
79 | ~nsEmbedString()
|
---|
80 | {
|
---|
81 | NS_StringContainerFinish(*this);
|
---|
82 | }
|
---|
83 |
|
---|
84 | const char_type* get() const
|
---|
85 | {
|
---|
86 | const char_type* data;
|
---|
87 | NS_StringGetData(*this, &data);
|
---|
88 | return data;
|
---|
89 | }
|
---|
90 |
|
---|
91 | self_type& operator=(const self_type& aString) { Assign(aString); return *this; }
|
---|
92 | self_type& operator=(const abstract_string_type& aReadable) { Assign(aReadable); return *this; }
|
---|
93 | self_type& operator=(const char_type* aPtr) { Assign(aPtr); return *this; }
|
---|
94 | self_type& operator=(char_type aChar) { Assign(aChar); return *this; }
|
---|
95 | };
|
---|
96 |
|
---|
97 | class nsEmbedCString : public nsCStringContainer
|
---|
98 | {
|
---|
99 | public:
|
---|
100 | typedef nsEmbedCString self_type;
|
---|
101 | typedef nsACString abstract_string_type;
|
---|
102 |
|
---|
103 | nsEmbedCString()
|
---|
104 | #ifdef VBOX
|
---|
105 | : nsCStringContainer()
|
---|
106 | #endif
|
---|
107 | {
|
---|
108 | NS_CStringContainerInit(*this);
|
---|
109 | }
|
---|
110 |
|
---|
111 | nsEmbedCString(const self_type& aString)
|
---|
112 | #ifdef VBOX
|
---|
113 | : nsCStringContainer()
|
---|
114 | #endif
|
---|
115 | {
|
---|
116 | NS_CStringContainerInit(*this);
|
---|
117 | NS_CStringCopy(*this, aString);
|
---|
118 | }
|
---|
119 |
|
---|
120 | explicit
|
---|
121 | nsEmbedCString(const abstract_string_type& aReadable)
|
---|
122 | #ifdef VBOX
|
---|
123 | : nsCStringContainer()
|
---|
124 | #endif
|
---|
125 | {
|
---|
126 | NS_CStringContainerInit(*this);
|
---|
127 | NS_CStringCopy(*this, aReadable);
|
---|
128 | }
|
---|
129 |
|
---|
130 | explicit
|
---|
131 | nsEmbedCString(const char_type* aData, size_type aLength = PR_UINT32_MAX)
|
---|
132 | #ifdef VBOX
|
---|
133 | : nsCStringContainer()
|
---|
134 | #endif
|
---|
135 | {
|
---|
136 | NS_CStringContainerInit(*this);
|
---|
137 | NS_CStringSetData(*this, aData, aLength);
|
---|
138 | }
|
---|
139 |
|
---|
140 | ~nsEmbedCString()
|
---|
141 | {
|
---|
142 | NS_CStringContainerFinish(*this);
|
---|
143 | }
|
---|
144 |
|
---|
145 | const char_type* get() const
|
---|
146 | {
|
---|
147 | const char_type* data;
|
---|
148 | NS_CStringGetData(*this, &data);
|
---|
149 | return data;
|
---|
150 | }
|
---|
151 |
|
---|
152 | self_type& operator=(const self_type& aString) { Assign(aString); return *this; }
|
---|
153 | self_type& operator=(const abstract_string_type& aReadable) { Assign(aReadable); return *this; }
|
---|
154 | self_type& operator=(const char_type* aPtr) { Assign(aPtr); return *this; }
|
---|
155 | self_type& operator=(char_type aChar) { Assign(aChar); return *this; }
|
---|
156 | };
|
---|
157 |
|
---|
158 | #endif // !defined(nsEmbedString_h___)
|
---|