|
|
|||
File indexing completed on 2026-11-05 10:36:05
0001 // Copyright 2005, Google Inc. 0002 // All rights reserved. 0003 // 0004 // Redistribution and use in source and binary forms, with or without 0005 // modification, are permitted provided that the following conditions are 0006 // met: 0007 // 0008 // * Redistributions of source code must retain the above copyright 0009 // notice, this list of conditions and the following disclaimer. 0010 // * Redistributions in binary form must reproduce the above 0011 // copyright notice, this list of conditions and the following disclaimer 0012 // in the documentation and/or other materials provided with the 0013 // distribution. 0014 // * Neither the name of Google Inc. nor the names of its 0015 // contributors may be used to endorse or promote products derived from 0016 // this software without specific prior written permission. 0017 // 0018 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 0019 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 0020 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 0021 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 0022 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 0023 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 0024 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 0025 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 0026 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 0027 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 0028 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 0029 0030 // The Google C++ Testing and Mocking Framework (Google Test) 0031 // 0032 // This header file declares the String class and functions used internally by 0033 // Google Test. They are subject to change without notice. They should not used 0034 // by code external to Google Test. 0035 // 0036 // This header file is #included by gtest-internal.h. 0037 // It should not be #included by other files. 0038 0039 // IWYU pragma: private, include "gtest/gtest.h" 0040 // IWYU pragma: friend gtest/.* 0041 // IWYU pragma: friend gmock/.* 0042 0043 #ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_STRING_H_ 0044 #define GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_STRING_H_ 0045 0046 #ifdef __BORLANDC__ 0047 // string.h is not guaranteed to provide strcpy on C++ Builder. 0048 #include <mem.h> 0049 #endif 0050 0051 #include <string.h> 0052 0053 #include <cstdint> 0054 #include <sstream> 0055 #include <string> 0056 0057 #include "gtest/internal/gtest-port.h" 0058 0059 namespace testing { 0060 namespace internal { 0061 0062 // String - an abstract class holding static string utilities. 0063 class GTEST_API_ [[nodiscard]] String { 0064 public: 0065 // Static utility methods 0066 0067 // Clones a 0-terminated C string, allocating memory using new. The 0068 // caller is responsible for deleting the return value using 0069 // delete[]. Returns the cloned string, or NULL if the input is 0070 // NULL. 0071 // 0072 // This is different from strdup() in string.h, which allocates 0073 // memory using malloc(). 0074 static const char* CloneCString(const char* c_str); 0075 0076 #ifdef GTEST_OS_WINDOWS_MOBILE 0077 // Windows CE does not have the 'ANSI' versions of Win32 APIs. To be 0078 // able to pass strings to Win32 APIs on CE we need to convert them 0079 // to 'Unicode', UTF-16. 0080 0081 // Creates a UTF-16 wide string from the given ANSI string, allocating 0082 // memory using new. The caller is responsible for deleting the return 0083 // value using delete[]. Returns the wide string, or NULL if the 0084 // input is NULL. 0085 // 0086 // The wide string is created using the ANSI codepage (CP_ACP) to 0087 // match the behaviour of the ANSI versions of Win32 calls and the 0088 // C runtime. 0089 static LPCWSTR AnsiToUtf16(const char* c_str); 0090 0091 // Creates an ANSI string from the given wide string, allocating 0092 // memory using new. The caller is responsible for deleting the return 0093 // value using delete[]. Returns the ANSI string, or NULL if the 0094 // input is NULL. 0095 // 0096 // The returned string is created using the ANSI codepage (CP_ACP) to 0097 // match the behaviour of the ANSI versions of Win32 calls and the 0098 // C runtime. 0099 static const char* Utf16ToAnsi(LPCWSTR utf16_str); 0100 #endif 0101 0102 // Compares two C strings. Returns true if and only if they have the same 0103 // content. 0104 // 0105 // Unlike strcmp(), this function can handle NULL argument(s). A 0106 // NULL C string is considered different to any non-NULL C string, 0107 // including the empty string. 0108 static bool CStringEquals(const char* lhs, const char* rhs); 0109 0110 // Converts a wide C string to a String using the UTF-8 encoding. 0111 // NULL will be converted to "(null)". If an error occurred during 0112 // the conversion, "(failed to convert from wide string)" is 0113 // returned. 0114 static std::string ShowWideCString(const wchar_t* wide_c_str); 0115 0116 // Compares two wide C strings. Returns true if and only if they have the 0117 // same content. 0118 // 0119 // Unlike wcscmp(), this function can handle NULL argument(s). A 0120 // NULL C string is considered different to any non-NULL C string, 0121 // including the empty string. 0122 static bool WideCStringEquals(const wchar_t* lhs, const wchar_t* rhs); 0123 0124 // Compares two C strings, ignoring case. Returns true if and only if 0125 // they have the same content. 0126 // 0127 // Unlike strcasecmp(), this function can handle NULL argument(s). 0128 // A NULL C string is considered different to any non-NULL C string, 0129 // including the empty string. 0130 static bool CaseInsensitiveCStringEquals(const char* lhs, const char* rhs); 0131 0132 // Compares two wide C strings, ignoring case. Returns true if and only if 0133 // they have the same content. 0134 // 0135 // Unlike wcscasecmp(), this function can handle NULL argument(s). 0136 // A NULL C string is considered different to any non-NULL wide C string, 0137 // including the empty string. 0138 // NB: The implementations on different platforms slightly differ. 0139 // On windows, this method uses _wcsicmp which compares according to LC_CTYPE 0140 // environment variable. On GNU platform this method uses wcscasecmp 0141 // which compares according to LC_CTYPE category of the current locale. 0142 // On MacOS X, it uses towlower, which also uses LC_CTYPE category of the 0143 // current locale. 0144 static bool CaseInsensitiveWideCStringEquals(const wchar_t* lhs, 0145 const wchar_t* rhs); 0146 0147 // Returns true if and only if the given string ends with the given suffix, 0148 // ignoring case. Any string is considered to end with an empty suffix. 0149 static bool EndsWithCaseInsensitive(const std::string& str, 0150 const std::string& suffix); 0151 0152 // Formats an int value as "%02d". 0153 static std::string FormatIntWidth2(int value); // "%02d" for width == 2 0154 0155 // Formats an int value to given width with leading zeros. 0156 static std::string FormatIntWidthN(int value, int width); 0157 0158 // Formats an int value as "%X". 0159 static std::string FormatHexInt(int value); 0160 0161 // Formats an int value as "%X". 0162 static std::string FormatHexUInt32(uint32_t value); 0163 0164 // Formats a byte as "%02X". 0165 static std::string FormatByte(unsigned char value); 0166 0167 private: 0168 String(); // Not meant to be instantiated. 0169 }; // class String 0170 0171 // Gets the content of the stringstream's buffer as an std::string. Each '\0' 0172 // character in the buffer is replaced with "\\0". 0173 GTEST_API_ std::string StringStreamToString(::std::stringstream* stream); 0174 0175 } // namespace internal 0176 } // namespace testing 0177 0178 #endif // GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_STRING_H_
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|