gmock/gtest/include/gtest/internal/gtest-string.h
Go to the documentation of this file.
1 // Copyright 2005, Google Inc.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
13 // distribution.
14 // * Neither the name of Google Inc. nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // Authors: wan@google.com (Zhanyong Wan), eefacm@gmail.com (Sean Mcafee)
31 //
32 // The Google C++ Testing Framework (Google Test)
33 //
34 // This header file declares the String class and functions used internally by
35 // Google Test. They are subject to change without notice. They should not used
36 // by code external to Google Test.
37 //
38 // This header file is #included by <gtest/internal/gtest-internal.h>.
39 // It should not be #included by other files.
40 
41 #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_STRING_H_
42 #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_STRING_H_
43 
44 #ifdef __BORLANDC__
45 // string.h is not guaranteed to provide strcpy on C++ Builder.
46 # include <mem.h>
47 #endif
48 
49 #include <string.h>
50 #include <string>
51 
52 #include "gtest/internal/gtest-port.h"
53 
54 namespace testing
55 {
56 namespace internal
57 {
58 
59 // String - an abstract class holding static string utilities.
60 class GTEST_API_ String
61 {
62 public:
63  // Static utility methods
64 
65  // Clones a 0-terminated C string, allocating memory using new. The
66  // caller is responsible for deleting the return value using
67  // delete[]. Returns the cloned string, or NULL if the input is
68  // NULL.
69  //
70  // This is different from strdup() in string.h, which allocates
71  // memory using malloc().
72  static const char * CloneCString(const char * c_str);
73 
74 #if GTEST_OS_WINDOWS_MOBILE
75  // Windows CE does not have the 'ANSI' versions of Win32 APIs. To be
76  // able to pass strings to Win32 APIs on CE we need to convert them
77  // to 'Unicode', UTF-16.
78 
79  // Creates a UTF-16 wide string from the given ANSI string, allocating
80  // memory using new. The caller is responsible for deleting the return
81  // value using delete[]. Returns the wide string, or NULL if the
82  // input is NULL.
83  //
84  // The wide string is created using the ANSI codepage (CP_ACP) to
85  // match the behaviour of the ANSI versions of Win32 calls and the
86  // C runtime.
87  static LPCWSTR AnsiToUtf16(const char * c_str);
88 
89  // Creates an ANSI string from the given wide string, allocating
90  // memory using new. The caller is responsible for deleting the return
91  // value using delete[]. Returns the ANSI string, or NULL if the
92  // input is NULL.
93  //
94  // The returned string is created using the ANSI codepage (CP_ACP) to
95  // match the behaviour of the ANSI versions of Win32 calls and the
96  // C runtime.
97  static const char * Utf16ToAnsi(LPCWSTR utf16_str);
98 #endif
99 
100  // Compares two C strings. Returns true iff they have the same content.
101  //
102  // Unlike strcmp(), this function can handle NULL argument(s). A
103  // NULL C string is considered different to any non-NULL C string,
104  // including the empty string.
105  static bool CStringEquals(const char * lhs, const char * rhs);
106 
107  // Converts a wide C string to a String using the UTF-8 encoding.
108  // NULL will be converted to "(null)". If an error occurred during
109  // the conversion, "(failed to convert from wide string)" is
110  // returned.
111  static std::string ShowWideCString(const wchar_t * wide_c_str);
112 
113  // Compares two wide C strings. Returns true iff they have the same
114  // content.
115  //
116  // Unlike wcscmp(), this function can handle NULL argument(s). A
117  // NULL C string is considered different to any non-NULL C string,
118  // including the empty string.
119  static bool WideCStringEquals(const wchar_t * lhs, const wchar_t * rhs);
120 
121  // Compares two C strings, ignoring case. Returns true iff they
122  // have the same content.
123  //
124  // Unlike strcasecmp(), this function can handle NULL argument(s).
125  // A NULL C string is considered different to any non-NULL C string,
126  // including the empty string.
127  static bool CaseInsensitiveCStringEquals(const char * lhs,
128  const char * rhs);
129 
130  // Compares two wide C strings, ignoring case. Returns true iff they
131  // have the same content.
132  //
133  // Unlike wcscasecmp(), this function can handle NULL argument(s).
134  // A NULL C string is considered different to any non-NULL wide C string,
135  // including the empty string.
136  // NB: The implementations on different platforms slightly differ.
137  // On windows, this method uses _wcsicmp which compares according to LC_CTYPE
138  // environment variable. On GNU platform this method uses wcscasecmp
139  // which compares according to LC_CTYPE category of the current locale.
140  // On MacOS X, it uses towlower, which also uses LC_CTYPE category of the
141  // current locale.
142  static bool CaseInsensitiveWideCStringEquals(const wchar_t * lhs,
143  const wchar_t * rhs);
144 
145  // Returns true iff the given string ends with the given suffix, ignoring
146  // case. Any string is considered to end with an empty suffix.
147  static bool EndsWithCaseInsensitive(
148  const std::string & str, const std::string & suffix);
149 
150  // Formats an int value as "%02d".
151  static std::string FormatIntWidth2(int value); // "%02d" for width == 2
152 
153  // Formats an int value as "%X".
154  static std::string FormatHexInt(int value);
155 
156  // Formats a byte as "%02X".
157  static std::string FormatByte(unsigned char value);
158 
159 private:
160  String(); // Not meant to be instantiated.
161 }; // class String
162 
163 // Gets the content of the stringstream's buffer as an std::string. Each '\0'
164 // character in the buffer is replaced with "\\0".
165 GTEST_API_ std::string StringStreamToString(::std::stringstream * stream);
166 
167 } // namespace internal
168 } // namespace testing
169 
170 #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_STRING_H_
const char String[]
Definition: strings.h:192
#define GTEST_API_
std::string StringStreamToString(::std::stringstream *ss)
bool CaseInsensitiveCStringEquals(const char *lhs, const char *rhs)


ros_opcua_impl_freeopcua
Author(s): Denis Štogl
autogenerated on Tue Jan 19 2021 03:06:21