Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #ifndef nsString_h___
8 : #define nsString_h___
9 :
10 : #include "mozilla/Attributes.h"
11 :
12 : #include "nsSubstring.h"
13 : #include "nsDependentSubstring.h"
14 : #include "nsReadableUtils.h"
15 :
16 : #include <new>
17 :
18 : // enable support for the obsolete string API if not explicitly disabled
19 : #ifndef MOZ_STRING_WITH_OBSOLETE_API
20 : #define MOZ_STRING_WITH_OBSOLETE_API 1
21 : #endif
22 :
23 : #if MOZ_STRING_WITH_OBSOLETE_API
24 : // radix values for ToInteger/AppendInt
25 : #define kRadix10 (10)
26 : #define kRadix16 (16)
27 : #define kAutoDetect (100)
28 : #endif
29 :
30 :
31 : // declare nsString, et. al.
32 : #include "string-template-def-unichar.h"
33 : #include "nsTString.h"
34 : #include "string-template-undef.h"
35 :
36 : // declare nsCString, et. al.
37 : #include "string-template-def-char.h"
38 : #include "nsTString.h"
39 : #include "string-template-undef.h"
40 :
41 : static_assert(sizeof(char16_t) == 2, "size of char16_t must be 2");
42 : static_assert(sizeof(nsString::char_type) == 2,
43 : "size of nsString::char_type must be 2");
44 : static_assert(nsString::char_type(-1) > nsString::char_type(0),
45 : "nsString::char_type must be unsigned");
46 : static_assert(sizeof(nsCString::char_type) == 1,
47 : "size of nsCString::char_type must be 1");
48 :
49 :
50 : /**
51 : * A helper class that converts a UTF-16 string to ASCII in a lossy manner
52 : */
53 109 : class NS_LossyConvertUTF16toASCII : public nsAutoCString
54 : {
55 : public:
56 25 : explicit NS_LossyConvertUTF16toASCII(const char16ptr_t aString)
57 25 : {
58 25 : LossyAppendUTF16toASCII(aString, *this);
59 25 : }
60 :
61 : NS_LossyConvertUTF16toASCII(const char16ptr_t aString, uint32_t aLength)
62 : {
63 : LossyAppendUTF16toASCII(Substring(aString, aLength), *this);
64 : }
65 :
66 85 : explicit NS_LossyConvertUTF16toASCII(const nsAString& aString)
67 85 : {
68 85 : LossyAppendUTF16toASCII(aString, *this);
69 85 : }
70 :
71 : private:
72 : // NOT TO BE IMPLEMENTED
73 : NS_LossyConvertUTF16toASCII(char) = delete;
74 : };
75 :
76 :
77 678 : class NS_ConvertASCIItoUTF16 : public nsAutoString
78 : {
79 : public:
80 507 : explicit NS_ConvertASCIItoUTF16(const char* aCString)
81 507 : {
82 507 : AppendASCIItoUTF16(aCString, *this);
83 507 : }
84 :
85 0 : NS_ConvertASCIItoUTF16(const char* aCString, uint32_t aLength)
86 0 : {
87 0 : AppendASCIItoUTF16(Substring(aCString, aLength), *this);
88 0 : }
89 :
90 171 : explicit NS_ConvertASCIItoUTF16(const nsACString& aCString)
91 171 : {
92 171 : AppendASCIItoUTF16(aCString, *this);
93 171 : }
94 :
95 : private:
96 : // NOT TO BE IMPLEMENTED
97 : NS_ConvertASCIItoUTF16(char16_t) = delete;
98 : };
99 :
100 :
101 : /**
102 : * A helper class that converts a UTF-16 string to UTF-8
103 : */
104 1887 : class NS_ConvertUTF16toUTF8 : public nsAutoCString
105 : {
106 : public:
107 18 : explicit NS_ConvertUTF16toUTF8(const char16ptr_t aString)
108 18 : {
109 18 : AppendUTF16toUTF8(aString, *this);
110 18 : }
111 :
112 0 : NS_ConvertUTF16toUTF8(const char16ptr_t aString, uint32_t aLength)
113 0 : {
114 0 : AppendUTF16toUTF8(Substring(aString, aLength), *this);
115 0 : }
116 :
117 1872 : explicit NS_ConvertUTF16toUTF8(const nsAString& aString)
118 1872 : {
119 1872 : AppendUTF16toUTF8(aString, *this);
120 1872 : }
121 :
122 : private:
123 : // NOT TO BE IMPLEMENTED
124 : NS_ConvertUTF16toUTF8(char) = delete;
125 : };
126 :
127 :
128 569 : class NS_ConvertUTF8toUTF16 : public nsAutoString
129 : {
130 : public:
131 239 : explicit NS_ConvertUTF8toUTF16(const char* aCString)
132 239 : {
133 239 : AppendUTF8toUTF16(aCString, *this);
134 239 : }
135 :
136 0 : NS_ConvertUTF8toUTF16(const char* aCString, uint32_t aLength)
137 0 : {
138 0 : AppendUTF8toUTF16(Substring(aCString, aLength), *this);
139 0 : }
140 :
141 329 : explicit NS_ConvertUTF8toUTF16(const nsACString& aCString)
142 329 : {
143 329 : AppendUTF8toUTF16(aCString, *this);
144 329 : }
145 :
146 : private:
147 : // NOT TO BE IMPLEMENTED
148 : NS_ConvertUTF8toUTF16(char16_t) = delete;
149 : };
150 :
151 : // the following are included/declared for backwards compatibility
152 : typedef nsAutoString nsVoidableString;
153 :
154 : #include "nsDependentString.h"
155 : #include "nsLiteralString.h"
156 : #include "nsPromiseFlatString.h"
157 :
158 : // need to include these for backwards compatibility
159 : #include "nsMemory.h"
160 : #include <string.h>
161 : #include <stdio.h>
162 : #include "plhash.h"
163 :
164 : #endif // !defined(nsString_h___)
|