diff options
author | vladlosev <vladlosev@861a406c-534a-0410-8894-cb66d6ee9925> | 2008-11-26 20:48:45 +0000 |
---|---|---|
committer | vladlosev <vladlosev@861a406c-534a-0410-8894-cb66d6ee9925> | 2008-11-26 20:48:45 +0000 |
commit | 1998cf5d32a19aaffe8652545802744d9133022d (patch) | |
tree | d893f35c7534f4a9a3b3619ecf3331ed946d2c33 /include/gtest/internal/gtest-string.h | |
parent | 957ed9fb5210a8e0e51f713387961d2538921aed (diff) | |
download | googletest-1998cf5d32a19aaffe8652545802744d9133022d.tar.gz googletest-1998cf5d32a19aaffe8652545802744d9133022d.tar.bz2 googletest-1998cf5d32a19aaffe8652545802744d9133022d.zip |
Allow Google Mock to initialize Google Test
Diffstat (limited to 'include/gtest/internal/gtest-string.h')
-rw-r--r-- | include/gtest/internal/gtest-string.h | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/include/gtest/internal/gtest-string.h b/include/gtest/internal/gtest-string.h index b37ff4f4..178f14e1 100644 --- a/include/gtest/internal/gtest-string.h +++ b/include/gtest/internal/gtest-string.h @@ -44,6 +44,10 @@ #include <string.h> #include <gtest/internal/gtest-port.h> +#if GTEST_HAS_GLOBAL_STRING || GTEST_HAS_STD_STRING +#include <string> +#endif // GTEST_HAS_GLOBAL_STRING || GTEST_HAS_STD_STRING + namespace testing { namespace internal { @@ -217,6 +221,24 @@ class String { // doesn't need to be virtual. ~String() { delete[] c_str_; } + // Allows a String to be implicitly converted to an ::std::string or + // ::string, and vice versa. Converting a String containing a NULL + // pointer to ::std::string or ::string is undefined behavior. + // Converting a ::std::string or ::string containing an embedded NUL + // character to a String will result in the prefix up to the first + // NUL character. +#if GTEST_HAS_STD_STRING + String(const ::std::string& str) : c_str_(NULL) { *this = str.c_str(); } + + operator ::std::string() const { return ::std::string(c_str_); } +#endif // GTEST_HAS_STD_STRING + +#if GTEST_HAS_GLOBAL_STRING + String(const ::string& str) : c_str_(NULL) { *this = str.c_str(); } + + operator ::string() const { return ::string(c_str_); } +#endif // GTEST_HAS_GLOBAL_STRING + // Returns true iff this is an empty string (i.e. ""). bool empty() const { return (c_str_ != NULL) && (*c_str_ == '\0'); |