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 : * Darin Fisher <darin@meer.net>
24 : *
25 : * Alternatively, the contents of this file may be used under the terms of
26 : * either the GNU General Public License Version 2 or later (the "GPL"), or
27 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 : * in which case the provisions of the GPL or the LGPL are applicable instead
29 : * of those above. If you wish to allow use of your version of this file only
30 : * under the terms of either the GPL or the LGPL, and not to allow others to
31 : * use your version of this file under the terms of the MPL, indicate your
32 : * decision by deleting the provisions above and replace them with the notice
33 : * and other provisions required by the GPL or the LGPL. If you do not delete
34 : * the provisions above, a recipient may use your version of this file under
35 : * the terms of any one of the MPL, the GPL or the LGPL.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 :
39 : #ifndef nsString_h___
40 : #define nsString_h___
41 :
42 : #include "mozilla/Attributes.h"
43 :
44 : #ifndef nsSubstring_h___
45 : #include "nsSubstring.h"
46 : #endif
47 :
48 : #ifndef nsDependentSubstring_h___
49 : #include "nsDependentSubstring.h"
50 : #endif
51 :
52 : #ifndef nsReadableUtils_h___
53 : #include "nsReadableUtils.h"
54 : #endif
55 :
56 : #include NEW_H
57 :
58 : // enable support for the obsolete string API if not explicitly disabled
59 : #ifndef MOZ_STRING_WITH_OBSOLETE_API
60 : #define MOZ_STRING_WITH_OBSOLETE_API 1
61 : #endif
62 :
63 : #if MOZ_STRING_WITH_OBSOLETE_API
64 : // radix values for ToInteger/AppendInt
65 : #define kRadix10 (10)
66 : #define kRadix16 (16)
67 : #define kAutoDetect (100)
68 : #define kRadixUnknown (kAutoDetect+1)
69 : #define IGNORE_CASE (true)
70 : #endif
71 :
72 :
73 : // declare nsString, et. al.
74 : #include "string-template-def-unichar.h"
75 : #include "nsTString.h"
76 : #include "string-template-undef.h"
77 :
78 : // declare nsCString, et. al.
79 : #include "string-template-def-char.h"
80 : #include "nsTString.h"
81 : #include "string-template-undef.h"
82 :
83 : PR_STATIC_ASSERT(sizeof(PRUnichar) == 2);
84 : PR_STATIC_ASSERT(sizeof(nsString::char_type) == 2);
85 : PR_STATIC_ASSERT(sizeof(nsCString::char_type) == 1);
86 :
87 : /**
88 : * A helper class that converts a UTF-16 string to ASCII in a lossy manner
89 : */
90 : class NS_LossyConvertUTF16toASCII : public nsCAutoString
91 776 : {
92 : public:
93 : explicit
94 31 : NS_LossyConvertUTF16toASCII( const PRUnichar* aString )
95 31 : {
96 31 : LossyAppendUTF16toASCII(aString, *this);
97 31 : }
98 :
99 : NS_LossyConvertUTF16toASCII( const PRUnichar* aString, PRUint32 aLength )
100 : {
101 : LossyAppendUTF16toASCII(Substring(aString, aLength), *this);
102 : }
103 :
104 : explicit
105 745 : NS_LossyConvertUTF16toASCII( const nsAString& aString )
106 745 : {
107 745 : LossyAppendUTF16toASCII(aString, *this);
108 745 : }
109 :
110 : private:
111 : // NOT TO BE IMPLEMENTED
112 : NS_LossyConvertUTF16toASCII( char );
113 : };
114 :
115 :
116 : class NS_ConvertASCIItoUTF16 : public nsAutoString
117 517920 : {
118 : public:
119 : explicit
120 512834 : NS_ConvertASCIItoUTF16( const char* aCString )
121 512834 : {
122 512834 : AppendASCIItoUTF16(aCString, *this);
123 512834 : }
124 :
125 229 : NS_ConvertASCIItoUTF16( const char* aCString, PRUint32 aLength )
126 229 : {
127 229 : AppendASCIItoUTF16(Substring(aCString, aLength), *this);
128 229 : }
129 :
130 : explicit
131 4857 : NS_ConvertASCIItoUTF16( const nsACString& aCString )
132 4857 : {
133 4857 : AppendASCIItoUTF16(aCString, *this);
134 4857 : }
135 :
136 : private:
137 : // NOT TO BE IMPLEMENTED
138 : NS_ConvertASCIItoUTF16( PRUnichar );
139 : };
140 :
141 :
142 : /**
143 : * A helper class that converts a UTF-16 string to UTF-8
144 : */
145 : class NS_ConvertUTF16toUTF8 : public nsCAutoString
146 590037 : {
147 : public:
148 : explicit
149 50071 : NS_ConvertUTF16toUTF8( const PRUnichar* aString )
150 50071 : {
151 50071 : AppendUTF16toUTF8(aString, *this);
152 50071 : }
153 :
154 150697 : NS_ConvertUTF16toUTF8( const PRUnichar* aString, PRUint32 aLength )
155 150697 : {
156 150697 : AppendUTF16toUTF8(Substring(aString, aLength), *this);
157 150697 : }
158 :
159 : explicit
160 389269 : NS_ConvertUTF16toUTF8( const nsAString& aString )
161 389269 : {
162 389269 : AppendUTF16toUTF8(aString, *this);
163 389269 : }
164 :
165 : private:
166 : // NOT TO BE IMPLEMENTED
167 : NS_ConvertUTF16toUTF8( char );
168 : };
169 :
170 :
171 : class NS_ConvertUTF8toUTF16 : public nsAutoString
172 40107 : {
173 : public:
174 : explicit
175 3403 : NS_ConvertUTF8toUTF16( const char* aCString )
176 3403 : {
177 3403 : AppendUTF8toUTF16(aCString, *this);
178 3403 : }
179 :
180 7098 : NS_ConvertUTF8toUTF16( const char* aCString, PRUint32 aLength )
181 7098 : {
182 7098 : AppendUTF8toUTF16(Substring(aCString, aLength), *this);
183 7098 : }
184 :
185 : explicit
186 29606 : NS_ConvertUTF8toUTF16( const nsACString& aCString )
187 29606 : {
188 29606 : AppendUTF8toUTF16(aCString, *this);
189 29606 : }
190 :
191 : private:
192 : // NOT TO BE IMPLEMENTED
193 : NS_ConvertUTF8toUTF16( PRUnichar );
194 : };
195 :
196 :
197 : // the following are included/declared for backwards compatibility
198 : typedef nsAutoString nsVoidableString;
199 :
200 : #ifndef nsDependentString_h___
201 : #include "nsDependentString.h"
202 : #endif
203 :
204 : #ifndef nsLiteralString_h___
205 : #include "nsLiteralString.h"
206 : #endif
207 :
208 : #ifndef nsPromiseFlatString_h___
209 : #include "nsPromiseFlatString.h"
210 : #endif
211 :
212 : // need to include these for backwards compatibility
213 : #include "nsMemory.h"
214 : #include <string.h>
215 : #include <stdio.h>
216 : #include "plhash.h"
217 :
218 0 : inline PRInt32 MinInt(PRInt32 x, PRInt32 y)
219 : {
220 0 : return NS_MIN(x, y);
221 : }
222 :
223 0 : inline PRInt32 MaxInt(PRInt32 x, PRInt32 y)
224 : {
225 0 : return NS_MAX(x, y);
226 : }
227 :
228 : /**
229 : * Deprecated: don't use |Recycle|, just call |nsMemory::Free| directly
230 : *
231 : * Return the given buffer to the heap manager. Calls allocator::Free()
232 : */
233 : inline void Recycle( char* aBuffer) { nsMemory::Free(aBuffer); }
234 : inline void Recycle( PRUnichar* aBuffer) { nsMemory::Free(aBuffer); }
235 :
236 : #endif // !defined(nsString_h___)
|