Home | History | Annotate | Download | only in internal

Lines Matching defs:string

34 // This header file declares the String class and functions used internally by
45 // string.h is not guaranteed to provide strcpy on C++ Builder.
49 #include <string.h>
50 #include <string>
57 // String - a UTF-8 string class.
59 // For historic reasons, we don't use std::string.
61 // TODO(wan@google.com): replace this class with std::string or
64 // Note that String can represent both NULL and the empty string,
65 // while std::string cannot represent NULL.
67 // NULL and the empty string are considered different. NULL is less
68 // than anything (including the empty string) except itself.
72 // string class here.
75 // std::string on platforms where it cannot be used, we define a copy
79 // In order to make the representation efficient, the d'tor of String
80 // is not virtual. Therefore DO NOT INHERIT FROM String.
81 class GTEST_API_ String {
89 // This is useful for printing a C string in the syntax of a literal.
92 static String ShowCStringQuoted(const char* c_str);
94 // Clones a 0-terminated C string, allocating memory using new. The
96 // delete[]. Returns the cloned string, or NULL if the input is
99 // This is different from strdup() in string.h, which allocates
108 // Creates a UTF-16 wide string from the given ANSI string, allocating
110 // value using delete[]. Returns the wide string, or NULL if the
113 // The wide string is created using the ANSI codepage (CP_ACP) to
118 // Creates an ANSI string from the given wide string, allocating
120 // value using delete[]. Returns the ANSI string, or NULL if the
123 // The returned string is created using the ANSI codepage (CP_ACP) to
132 // NULL C string is considered different to any non-NULL C string,
133 // including the empty string.
136 // Converts a wide C string to a String using the UTF-8 encoding.
138 // the conversion, "(failed to convert from wide string)" is
140 static String ShowWideCString(const wchar_t* wide_c_str);
143 // the converted string in double quotes.
144 static String ShowWideCStringQuoted(const wchar_t* wide_c_str);
150 // NULL C string is considered different to any non-NULL C string,
151 // including the empty string.
158 // A NULL C string is considered different to any non-NULL C string,
159 // including the empty string.
167 // A NULL C string is considered different to any non-NULL wide C string,
168 // including the empty string.
178 // Formats a list of arguments to a String, using the same format
179 // spec string as for printf.
187 static String Format(const char* format, ...);
191 // The default c'tor constructs a NULL string.
192 String() : c_str_(NULL), length_(0) {}
194 // Constructs a String by cloning a 0-terminated C string.
195 String(const char* a_c_str) { // NOLINT
204 // Constructs a String by copying a given number of chars from a
205 // buffer. E.g. String("hello", 3) creates the string "hel",
206 // String("a\0bcd", 4) creates "a\0bc", String(NULL, 0) creates "",
207 // and String(NULL, 1) results in access violation.
208 String(const char* buffer, size_t a_length) {
212 // The copy c'tor creates a new copy of the string. The two
213 // String objects do not share content.
214 String(const String& str) : c_str_(NULL), length_(0) { *this = str; }
216 // D'tor. String is intended to be a final class, so the d'tor
218 ~String() { delete[] c_str_; }
220 // Allows a String to be implicitly converted to an ::std::string or
221 // ::string, and vice versa. Converting a String containing a NULL
222 // pointer to ::std::string or ::string is undefined behavior.
223 // Converting a ::std::string or ::string containing an embedded NUL
224 // character to a String will result in the prefix up to the first
226 String(const ::std::string& str) { // NOLINT
230 operator ::std::string() const { return ::std::string(c_str(), length()); }
233 String(const ::string& str) { // NOLINT
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* a_c_str) {
279 return *this = String(a_c_str);
282 // Assigns a String object to this object. Self-assignment works.
283 const String& operator=(const String& rhs) {
298 // Constructs a non-NULL String from the given content. This
300 // ConstructNonNull(NULL, 0) results in an empty string ("").
312 }; // class String
314 // Streams a String to an ostream. Each '\0' character in the String
316 inline ::std::ostream& operator<<(::std::ostream& os, const String& str) {
332 // Gets the content of the stringstream's buffer as a String. Each '\0'
334 GTEST_API_ String StringStreamToString(::std::stringstream* stream);
336 // Converts a streamable value to a String. A NULL pointer is
337 // converted to "(null)". When the input value is a ::string,
338 // ::std::string, ::wstring, or ::std::wstring object, each NUL
345 String StreamableToString(const T& streamable);