summaryrefslogtreecommitdiff
path: root/absl/strings/escaping.cc
diff options
context:
space:
mode:
Diffstat (limited to 'absl/strings/escaping.cc')
-rw-r--r--absl/strings/escaping.cc24
1 files changed, 13 insertions, 11 deletions
diff --git a/absl/strings/escaping.cc b/absl/strings/escaping.cc
index 9874f492..69053c19 100644
--- a/absl/strings/escaping.cc
+++ b/absl/strings/escaping.cc
@@ -33,7 +33,7 @@
#include "absl/strings/string_view.h"
namespace absl {
-inline namespace lts_2018_06_20 {
+inline namespace lts_2018_12_18 {
namespace {
// Digit conversion.
@@ -90,7 +90,7 @@ inline bool IsSurrogate(char32_t c, absl::string_view src, std::string* error) {
//
// Unescapes C escape sequences and is the reverse of CEscape().
//
-// If 'source' is valid, stores the unescaped std::string and its size in
+// If 'source' is valid, stores the unescaped string and its size in
// 'dest' and 'dest_len' respectively, and returns true. Otherwise
// returns false and optionally stores the error description in
// 'error'. Set 'error' to nullptr to disable error reporting.
@@ -105,7 +105,7 @@ bool CUnescapeInternal(absl::string_view source, bool leave_nulls_escaped,
char* dest, ptrdiff_t* dest_len, std::string* error) {
char* d = dest;
const char* p = source.data();
- const char* end = source.end();
+ const char* end = p + source.size();
const char* last_byte = end - 1;
// Small optimization for case where source = dest and there's no escaping
@@ -295,7 +295,7 @@ bool CUnescapeInternal(absl::string_view source, bool leave_nulls_escaped,
// ----------------------------------------------------------------------
// CUnescapeInternal()
//
-// Same as above but uses a C++ std::string for output. 'source' and 'dest'
+// Same as above but uses a C++ string for output. 'source' and 'dest'
// may be the same.
// ----------------------------------------------------------------------
bool CUnescapeInternal(absl::string_view source, bool leave_nulls_escaped,
@@ -305,7 +305,7 @@ bool CUnescapeInternal(absl::string_view source, bool leave_nulls_escaped,
ptrdiff_t dest_size;
if (!CUnescapeInternal(source,
leave_nulls_escaped,
- const_cast<char*>(dest->data()),
+ &(*dest)[0],
&dest_size,
error)) {
return false;
@@ -685,7 +685,7 @@ bool Base64UnescapeInternal(const char* src_param, size_t szsrc, char* dest,
// The arrays below were generated by the following code
// #include <sys/time.h>
// #include <stdlib.h>
-// #include <std::string.h>
+// #include <string.h>
// main()
// {
// static const char Base64[] =
@@ -940,7 +940,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);
@@ -952,7 +953,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.
@@ -1000,7 +1002,7 @@ constexpr char kHexValue[256] = {
/* clang-format on */
// This is a templated function so that T can be either a char*
-// or a std::string. This works because we use the [] operator to access
+// or a string. This works because we use the [] operator to access
// individual characters at a time.
template <typename T>
void HexStringToBytesInternal(const char* from, T to, ptrdiff_t num) {
@@ -1010,7 +1012,7 @@ void HexStringToBytesInternal(const char* from, T to, ptrdiff_t num) {
}
}
-// This is a templated function so that T can be either a char* or a std::string.
+// This is a templated function so that T can be either a char* or a string.
template <typename T>
void BytesToHexStringInternal(const unsigned char* src, T dest, ptrdiff_t num) {
auto dest_ptr = &dest[0];
@@ -1107,5 +1109,5 @@ std::string BytesToHexString(absl::string_view from) {
return result;
}
-} // inline namespace lts_2018_06_20
+} // inline namespace lts_2018_12_18
} // namespace absl