Lines Matching defs:string
34 // This header file declares the String class and functions used internally by
44 #include <string.h>
48 #include <string>
54 // String - a UTF-8 string class.
56 // We cannot use std::string as Microsoft's STL implementation in
61 // Also, String is different from std::string in that it can represent
62 // both NULL and the empty string, while std::string cannot represent
65 // NULL and the empty string are considered different. NULL is less
66 // than anything (including the empty string) except itself.
70 // string class here.
73 // std::string on platforms where it cannot be used, we define a copy
77 // In order to make the representation efficient, the d'tor of String
78 // is not virtual. Therefore DO NOT INHERIT FROM String.
79 class String {
87 // This is useful for printing a C string in the syntax of a literal.
90 static String ShowCStringQuoted(const char* c_str);
92 // Clones a 0-terminated C string, allocating memory using new. The
94 // delete[]. Returns the cloned string, or NULL if the input is
97 // This is different from strdup() in string.h, which allocates
106 // Creates a UTF-16 wide string from the given ANSI string, allocating
108 // value using delete[]. Returns the wide string, or NULL if the
111 // The wide string is created using the ANSI codepage (CP_ACP) to
116 // Creates an ANSI string from the given wide string, allocating
118 // value using delete[]. Returns the ANSI string, or NULL if the
121 // The returned string is created using the ANSI codepage (CP_ACP) to
130 // NULL C string is considered different to any non-NULL C string,
131 // including the empty string.
134 // Converts a wide C string to a String using the UTF-8 encoding.
136 // the conversion, "(failed to convert from wide string)" is
138 static String ShowWideCString(const wchar_t* wide_c_str);
141 // the converted string in double quotes.
142 static String ShowWideCStringQuoted(const wchar_t* wide_c_str);
148 // NULL C string is considered different to any non-NULL C string,
149 // including the empty string.
156 // A NULL C string is considered different to any non-NULL C string,
157 // including the empty string.
165 // A NULL C string is considered different to any non-NULL wide C string,
166 // including the empty string.
176 // Formats a list of arguments to a String, using the same format
177 // spec string as for printf.
185 static String Format(const char* format, ...);
189 // The default c'tor constructs a NULL string.
190 String() : c_str_(NULL), length_(0) {}
192 // Constructs a String by cloning a 0-terminated C string.
193 String(const char* c_str) { // NOLINT
202 // Constructs a String by copying a given number of chars from a
203 // buffer. E.g. String("hello", 3) creates the string "hel",
204 // String("a\0bcd", 4) creates "a\0bc", String(NULL, 0) creates "",
205 // and String(NULL, 1) results in access violation.
206 String(const char* buffer, size_t length) {
210 // The copy c'tor creates a new copy of the string. The two
211 // String objects do not share content.
212 String(const String& str) : c_str_(NULL), length_(0) { *this = str; }
214 // D'tor. String is intended to be a final class, so the d'tor
216 ~String() { delete[] c_str_; }
218 // Allows a String to be implicitly converted to an ::std::string or
219 // ::string, and vice versa. Converting a String containing a NULL
220 // pointer to ::std::string or ::string is undefined behavior.
221 // Converting a ::std::string or ::string containing an embedded NUL
222 // character to a String will result in the prefix up to the first
225 String(const ::std::string& str) {
229 operator ::std::string() const { return ::std::string(c_str(), length()); }
233 String(const ::string& str) {
237 operator ::string() const { return ::string(c_str(), length()); }
240 // Returns true iff this is an empty string (i.e. "").
243 // Compares this with another String.
246 int Compare(const String& rhs) const;
248 // Returns true iff this String equals the given C string. A NULL
249 // string and a non-NULL string are considered not equal.
252 // Returns true iff this String is less than the given String. A
253 // NULL string is considered less than "".
254 bool operator<(const String& rhs) const { return Compare(rhs) < 0; }
256 // Returns true iff this String doesn't equal the given C string. A NULL
257 // string and a non-NULL string are considered not equal.
260 // Returns true iff this String ends with the given suffix. *Any*
261 // String is considered to end with a NULL or empty suffix.
264 // Returns true iff this String ends with the given suffix, not considering
265 // case. Any String is considered to end with a NULL or empty suffix.
268 // Returns the length of the encapsulated string, or 0 if the
269 // string is NULL.
272 // Gets the 0-terminated C string this String object represents.
273 // The String object still owns the string. Therefore the caller
277 // Assigns a C string to this object. Self-assignment works.
278 const String& operator=(const char* c_str) { return *this = String(c_str); }
280 // Assigns a String object to this object. Self-assignment works.
281 const String& operator=(const String& rhs) {
296 // Constructs a non-NULL String from the given content. This
298 // ConstructNonNull(NULL, 0) results in an empty string ("").
310 }; // class String
312 // Streams a String to an ostream. Each '\0' character in the String
314 inline ::std::ostream& operator<<(::std::ostream& os, const String& str) {
330 // Gets the content of the StrStream's buffer as a String. Each '\0'
332 String StrStreamToString(StrStream* stream);
334 // Converts a streamable value to a String. A NULL pointer is
335 // converted to "(null)". When the input value is a ::string,
336 // ::std::string, ::wstring, or ::std::wstring object, each NUL
343 String StreamableToString(const T& streamable);