summaryrefslogtreecommitdiff
path: root/absl/strings
diff options
context:
space:
mode:
authorGravatar Abseil Team <absl-team@google.com>2018-09-05 10:20:22 -0700
committerGravatar Mark Barolak <mbar@google.com>2018-09-05 15:21:18 -0400
commitfb462224c058487763f263b7995d70efd0242c17 (patch)
tree0ae54439d31e8190ca34cac0da912a6daa78fa85 /absl/strings
parentc075ad321696fa5072e097f0a51e4fe76a6fe13e (diff)
Export of internal Abseil changes.
-- 86b1c997fac1f77b0eacfab788659b5a89a6096e by Abseil Team <absl-team@google.com>: Import of CCTZ from GitHub. PiperOrigin-RevId: 211654320 -- 299b70e1247df768454a76eb957a184de9706f61 by Chris Kennelly <ckennelly@google.com>: Avoid creating a misaligned reference to int. PiperOrigin-RevId: 211505883 -- c8fad4357ad0bfb3c5ad197c505509bc087072c9 by Abseil Team <absl-team@google.com>: Import of CCTZ from GitHub. PiperOrigin-RevId: 211458539 -- 0613feffcd36466c3e53a50758d7e8f17c001dce by Greg Falcon <gfalcon@google.com>: Refactor a string unit test into a template function for internal purposes. PiperOrigin-RevId: 211100748 GitOrigin-RevId: 86b1c997fac1f77b0eacfab788659b5a89a6096e Change-Id: Ic6a932b6c27c6762dcdb3b0127f1e2be782418c1
Diffstat (limited to 'absl/strings')
-rw-r--r--absl/strings/escaping.cc6
-rw-r--r--absl/strings/escaping_test.cc17
-rw-r--r--absl/strings/str_format_test.cc2
3 files changed, 16 insertions, 9 deletions
diff --git a/absl/strings/escaping.cc b/absl/strings/escaping.cc
index 6742f446..8d8b00b2 100644
--- a/absl/strings/escaping.cc
+++ b/absl/strings/escaping.cc
@@ -939,7 +939,8 @@ constexpr char kBase64Chars[] =
constexpr char kWebSafeBase64Chars[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
-void Base64EscapeInternal(const unsigned char* src, size_t szsrc, std::string* dest,
+template <typename String>
+void Base64EscapeInternal(const unsigned char* src, size_t szsrc, String* dest,
bool do_padding, const char* base64_chars) {
const size_t calc_escaped_size =
CalculateBase64EscapedLenInternal(szsrc, do_padding);
@@ -951,7 +952,8 @@ void Base64EscapeInternal(const unsigned char* src, size_t szsrc, std::string* d
dest->erase(escaped_len);
}
-bool Base64UnescapeInternal(const char* src, size_t slen, std::string* dest,
+template <typename String>
+bool Base64UnescapeInternal(const char* src, size_t slen, String* dest,
const signed char* unbase64) {
// Determine the size of the output std::string. Base64 encodes every 3 bytes into
// 4 characters. any leftover chars are added directly for good measure.
diff --git a/absl/strings/escaping_test.cc b/absl/strings/escaping_test.cc
index 3f65ec10..9dc27f3f 100644
--- a/absl/strings/escaping_test.cc
+++ b/absl/strings/escaping_test.cc
@@ -543,18 +543,19 @@ static struct {
{"abcdefghijklmnopqrstuvwxyz", "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXo="},
};
-TEST(Base64, EscapeAndUnescape) {
+template <typename StringType>
+void TestEscapeAndUnescape() {
// Check the short strings; this tests the math (and boundaries)
for (const auto& tc : base64_tests) {
- std::string encoded("this junk should be ignored");
+ StringType encoded("this junk should be ignored");
absl::Base64Escape(tc.plaintext, &encoded);
EXPECT_EQ(encoded, tc.cyphertext);
- std::string decoded("this junk should be ignored");
+ StringType decoded("this junk should be ignored");
EXPECT_TRUE(absl::Base64Unescape(encoded, &decoded));
EXPECT_EQ(decoded, tc.plaintext);
- std::string websafe(tc.cyphertext);
+ StringType websafe(tc.cyphertext);
for (int c = 0; c < websafe.size(); ++c) {
if ('+' == websafe[c]) websafe[c] = '-';
if ('/' == websafe[c]) websafe[c] = '_';
@@ -576,7 +577,7 @@ TEST(Base64, EscapeAndUnescape) {
// Now try the long strings, this tests the streaming
for (const auto& tc : absl::strings_internal::base64_strings()) {
- std::string buffer;
+ StringType buffer;
absl::WebSafeBase64Escape(tc.plaintext, &buffer);
EXPECT_EQ(tc.cyphertext, buffer);
}
@@ -586,7 +587,7 @@ TEST(Base64, EscapeAndUnescape) {
absl::string_view data_set[] = {"ab-/", absl::string_view("\0bcd", 4),
absl::string_view("abc.\0", 5)};
for (absl::string_view bad_data : data_set) {
- std::string buf;
+ StringType buf;
EXPECT_FALSE(absl::Base64Unescape(bad_data, &buf));
EXPECT_FALSE(absl::WebSafeBase64Unescape(bad_data, &buf));
EXPECT_TRUE(buf.empty());
@@ -594,6 +595,10 @@ TEST(Base64, EscapeAndUnescape) {
}
}
+TEST(Base64, EscapeAndUnescape) {
+ TestEscapeAndUnescape<std::string>();
+}
+
TEST(Base64, DISABLED_HugeData) {
const size_t kSize = size_t(3) * 1000 * 1000 * 1000;
static_assert(kSize % 3 == 0, "kSize must be divisible by 3");
diff --git a/absl/strings/str_format_test.cc b/absl/strings/str_format_test.cc
index fed75faf..9a6576dc 100644
--- a/absl/strings/str_format_test.cc
+++ b/absl/strings/str_format_test.cc
@@ -391,7 +391,7 @@ TEST(StrFormat, BehavesAsDocumented) {
#endif
// Other conversion
- int64_t value = 0x7ffdeb6;
+ int64_t value = 0x7ffdeb4;
auto ptr_value = static_cast<uintptr_t>(value);
const int& something = *reinterpret_cast<const int*>(ptr_value);
EXPECT_EQ(StrFormat("%p", &something), StrFormat("0x%x", ptr_value));