Export of internal Abseil changes.
-- ed4be0cb9a708158187a0628c1c2167ae6783274 by Greg Falcon <gfalcon@google.com>: Refactor a string unit test into a template function for internal purposes. PiperOrigin-RevId: 210798880 -- e4c734be903ac7b3a88caf4b17909343c283a21a by Abseil Team <absl-team@google.com>: Add a note that the RFC3339_* format specifiers use %Y, and so do not produce 4-digit years on output nor require 4-digit years on input, as a strict reading of RFC3339 might require. PiperOrigin-RevId: 210785544 -- cfb5e32f9397e49ddb731445a191b36652fe2f6d by Greg Falcon <gfalcon@google.com>: Refactor a string unit test into a template function for internal purposes. PiperOrigin-RevId: 210776525 -- 105ee700e62869cfda2a37e6f7c2ea483f8fc75e by Xiaoyi Zhang <zhangxy@google.com>: Correctly define ABSL_HAVE_STD_STRING_VIEW for MSVC 2017. Currently the macro is not defined even though MSVC 2017 provides `std::string_view`, and this means both `absl::string_view` and `std::string_view` exist as distinct types. A bunch of places relying on the false assumption that `string_view::const_iterator` is `const char*` have to be fixed to build successfully. See related github issue https://github.com/abseil/abseil-cpp/issues/161. PiperOrigin-RevId: 210764947 GitOrigin-RevId: ed4be0cb9a708158187a0628c1c2167ae6783274 Change-Id: I7a9658b3201aa669db9d3d90474feb08072718c7
This commit is contained in:
parent
6c7e5ffc43
commit
0f4bc96675
13 changed files with 36 additions and 29 deletions
|
@ -414,14 +414,13 @@
|
|||
// <string_view>, <variant> is implemented) or higher. Also, `__cplusplus` is
|
||||
// not correctly set by MSVC, so we use `_MSVC_LANG` to check the language
|
||||
// version.
|
||||
// TODO(zhangxy): fix tests before enabling aliasing for `std::any`,
|
||||
// `std::string_view`.
|
||||
// TODO(zhangxy): fix tests before enabling aliasing for `std::any`.
|
||||
#if defined(_MSC_VER) && _MSC_VER >= 1910 && \
|
||||
((defined(_MSVC_LANG) && _MSVC_LANG > 201402) || __cplusplus > 201402)
|
||||
// #define ABSL_HAVE_STD_ANY 1
|
||||
#define ABSL_HAVE_STD_OPTIONAL 1
|
||||
#define ABSL_HAVE_STD_VARIANT 1
|
||||
// #define ABSL_HAVE_STD_STRING_VIEW 1
|
||||
#define ABSL_HAVE_STD_STRING_VIEW 1
|
||||
#endif
|
||||
|
||||
#endif // ABSL_BASE_CONFIG_H_
|
||||
|
|
|
@ -195,7 +195,7 @@ ABSL_MUST_USE_RESULT inline std::string AsciiStrToUpper(absl::string_view s) {
|
|||
ABSL_MUST_USE_RESULT inline absl::string_view StripLeadingAsciiWhitespace(
|
||||
absl::string_view str) {
|
||||
auto it = std::find_if_not(str.begin(), str.end(), absl::ascii_isspace);
|
||||
return absl::string_view(it, str.end() - it);
|
||||
return str.substr(it - str.begin());
|
||||
}
|
||||
|
||||
// Strips in place whitespace from the beginning of the given string.
|
||||
|
@ -209,7 +209,7 @@ inline void StripLeadingAsciiWhitespace(std::string* str) {
|
|||
ABSL_MUST_USE_RESULT inline absl::string_view StripTrailingAsciiWhitespace(
|
||||
absl::string_view str) {
|
||||
auto it = std::find_if_not(str.rbegin(), str.rend(), absl::ascii_isspace);
|
||||
return absl::string_view(str.begin(), str.rend() - it);
|
||||
return str.substr(0, str.rend() - it);
|
||||
}
|
||||
|
||||
// Strips in place whitespace from the end of the given string
|
||||
|
|
|
@ -104,7 +104,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
|
||||
|
|
|
@ -69,10 +69,10 @@ class FILERawSink {
|
|||
|
||||
// Provide RawSink integration with common types from the STL.
|
||||
inline void AbslFormatFlush(std::string* out, string_view s) {
|
||||
out->append(s.begin(), s.size());
|
||||
out->append(s.data(), s.size());
|
||||
}
|
||||
inline void AbslFormatFlush(std::ostream* out, string_view s) {
|
||||
out->write(s.begin(), s.size());
|
||||
out->write(s.data(), s.size());
|
||||
}
|
||||
|
||||
template <class AbslCord, typename = typename std::enable_if<
|
||||
|
|
|
@ -81,8 +81,8 @@ static constexpr std::int8_t kIds[] = {
|
|||
template <bool is_positional>
|
||||
bool ConsumeConversion(string_view *src, UnboundConversion *conv,
|
||||
int *next_arg) {
|
||||
const char *pos = src->begin();
|
||||
const char *const end = src->end();
|
||||
const char *pos = src->data();
|
||||
const char *const end = pos + src->size();
|
||||
char c;
|
||||
// Read the next char into `c` and update `pos`. Reads '\0' if at end.
|
||||
const auto get_char = [&] { c = pos == end ? '\0' : *pos++; };
|
||||
|
|
|
@ -90,7 +90,7 @@ bool ParseFormatString(string_view src, Consumer consumer) {
|
|||
int next_arg = 0;
|
||||
while (!src.empty()) {
|
||||
const char* percent =
|
||||
static_cast<const char*>(memchr(src.begin(), '%', src.size()));
|
||||
static_cast<const char*>(memchr(src.data(), '%', src.size()));
|
||||
if (!percent) {
|
||||
// We found the last substring.
|
||||
return consumer.Append(src);
|
||||
|
@ -98,7 +98,7 @@ bool ParseFormatString(string_view src, Consumer consumer) {
|
|||
// We found a percent, so push the text run then process the percent.
|
||||
size_t percent_loc = percent - src.data();
|
||||
if (!consumer.Append(string_view(src.data(), percent_loc))) return false;
|
||||
if (percent + 1 >= src.end()) return false;
|
||||
if (percent + 1 >= src.data() + src.size()) return false;
|
||||
|
||||
UnboundConversion conv;
|
||||
|
||||
|
@ -178,7 +178,8 @@ class ParsedFormatBase {
|
|||
const char* const base = data_.get();
|
||||
string_view text(base, 0);
|
||||
for (const auto& item : items_) {
|
||||
text = string_view(text.end(), (base + item.text_end) - text.end());
|
||||
const char* const end = text.data() + text.size();
|
||||
text = string_view(end, (base + item.text_end) - end);
|
||||
if (item.is_conversion) {
|
||||
if (!consumer.ConvertOne(item.conv, text)) return false;
|
||||
} else {
|
||||
|
|
|
@ -66,10 +66,10 @@ class ConsumeUnboundConversionTest : public ::testing::Test {
|
|||
typedef UnboundConversion Props;
|
||||
string_view Consume(string_view* src) {
|
||||
int next = 0;
|
||||
const char* prev_begin = src->begin();
|
||||
const char* prev_begin = src->data();
|
||||
o = UnboundConversion(); // refresh
|
||||
ConsumeUnboundConversion(src, &o, &next);
|
||||
return {prev_begin, static_cast<size_t>(src->begin() - prev_begin)};
|
||||
return {prev_begin, static_cast<size_t>(src->data() - prev_begin)};
|
||||
}
|
||||
|
||||
bool Run(const char *fmt, bool force_positional = false) {
|
||||
|
|
|
@ -159,7 +159,7 @@ class SplitIterator {
|
|||
}
|
||||
const absl::string_view text = splitter_->text();
|
||||
const absl::string_view d = delimiter_.Find(text, pos_);
|
||||
if (d.data() == text.end()) state_ = kLastState;
|
||||
if (d.data() == text.data() + text.size()) state_ = kLastState;
|
||||
curr_ = text.substr(pos_, d.data() - (text.data() + pos_));
|
||||
pos_ += curr_.size() + d.size();
|
||||
} while (!predicate_(curr_));
|
||||
|
|
|
@ -43,10 +43,11 @@ absl::string_view GenericFind(absl::string_view text,
|
|||
if (delimiter.empty() && text.length() > 0) {
|
||||
// Special case for empty std::string delimiters: always return a zero-length
|
||||
// absl::string_view referring to the item at position 1 past pos.
|
||||
return absl::string_view(text.begin() + pos + 1, 0);
|
||||
return absl::string_view(text.data() + pos + 1, 0);
|
||||
}
|
||||
size_t found_pos = absl::string_view::npos;
|
||||
absl::string_view found(text.end(), 0); // By default, not found
|
||||
absl::string_view found(text.data() + text.size(),
|
||||
0); // By default, not found
|
||||
found_pos = find_policy.Find(text, delimiter, pos);
|
||||
if (found_pos != absl::string_view::npos) {
|
||||
found = absl::string_view(text.data() + found_pos,
|
||||
|
@ -87,7 +88,7 @@ absl::string_view ByString::Find(absl::string_view text, size_t pos) const {
|
|||
// absl::string_view.
|
||||
size_t found_pos = text.find(delimiter_[0], pos);
|
||||
if (found_pos == absl::string_view::npos)
|
||||
return absl::string_view(text.end(), 0);
|
||||
return absl::string_view(text.data() + text.size(), 0);
|
||||
return text.substr(found_pos, 1);
|
||||
}
|
||||
return GenericFind(text, delimiter_, pos, LiteralPolicy());
|
||||
|
@ -100,7 +101,7 @@ absl::string_view ByString::Find(absl::string_view text, size_t pos) const {
|
|||
absl::string_view ByChar::Find(absl::string_view text, size_t pos) const {
|
||||
size_t found_pos = text.find(c_, pos);
|
||||
if (found_pos == absl::string_view::npos)
|
||||
return absl::string_view(text.end(), 0);
|
||||
return absl::string_view(text.data() + text.size(), 0);
|
||||
return text.substr(found_pos, 1);
|
||||
}
|
||||
|
||||
|
@ -128,9 +129,9 @@ absl::string_view ByLength::Find(absl::string_view text,
|
|||
// If the std::string is shorter than the chunk size we say we
|
||||
// "can't find the delimiter" so this will be the last chunk.
|
||||
if (substr.length() <= static_cast<size_t>(length_))
|
||||
return absl::string_view(text.end(), 0);
|
||||
return absl::string_view(text.data() + text.size(), 0);
|
||||
|
||||
return absl::string_view(substr.begin() + length_, 0);
|
||||
return absl::string_view(substr.data() + length_, 0);
|
||||
}
|
||||
|
||||
} // namespace absl
|
||||
|
|
|
@ -261,7 +261,8 @@ class MaxSplitsImpl {
|
|||
: delimiter_(delimiter), limit_(limit), count_(0) {}
|
||||
absl::string_view Find(absl::string_view text, size_t pos) {
|
||||
if (count_++ == limit_) {
|
||||
return absl::string_view(text.end(), 0); // No more matches.
|
||||
return absl::string_view(text.data() + text.size(),
|
||||
0); // No more matches.
|
||||
}
|
||||
return delimiter_.Find(text, pos);
|
||||
}
|
||||
|
|
|
@ -763,7 +763,7 @@ template <typename Delimiter>
|
|||
static bool IsFoundAtStartingPos(absl::string_view text, Delimiter d,
|
||||
size_t starting_pos, int expected_pos) {
|
||||
absl::string_view found = d.Find(text, starting_pos);
|
||||
return found.data() != text.end() &&
|
||||
return found.data() != text.data() + text.size() &&
|
||||
expected_pos == found.data() - text.data();
|
||||
}
|
||||
|
||||
|
|
|
@ -816,11 +816,14 @@ TEST(StringViewTest, FrontBackSingleChar) {
|
|||
// libc++, it doesn't allow `nullptr` in the constexpr context, with the error
|
||||
// "read of dereferenced null pointer is not allowed in a constant expression".
|
||||
// At run time, the behavior of `std::char_traits::length()` on `nullptr` is
|
||||
// undefined by the standard and usually results in crash with libc++. This
|
||||
// conforms to the standard, but `absl::string_view` implements a different
|
||||
// undefined by the standard and usually results in crash with libc++.
|
||||
// In MSVC, creating a constexpr string_view from nullptr also triggers an
|
||||
// "unevaluable pointer value" error. This compiler implementation conforms
|
||||
// to the standard, but `absl::string_view` implements a different
|
||||
// behavior for historical reasons. We work around tests that construct
|
||||
// `string_view` from `nullptr` when using libc++.
|
||||
#if !defined(ABSL_HAVE_STD_STRING_VIEW) || !defined(_LIBCPP_VERSION)
|
||||
#if !defined(ABSL_HAVE_STD_STRING_VIEW) || \
|
||||
(!defined(_LIBCPP_VERSION) && !defined(_MSC_VER))
|
||||
#define ABSL_HAVE_STRING_VIEW_FROM_NULLPTR 1
|
||||
#endif // !defined(ABSL_HAVE_STD_STRING_VIEW) || !defined(_LIBCPP_VERSION)
|
||||
|
||||
|
|
|
@ -876,8 +876,10 @@ std::chrono::system_clock::time_point ToChronoTime(Time);
|
|||
// FormatTime()/ParseTime() format specifiers for RFC3339 date/time strings,
|
||||
// with trailing zeros trimmed or with fractional seconds omitted altogether.
|
||||
//
|
||||
// Note that RFC3339_sec[] matches an ISO 8601 extended format for date
|
||||
// and time with UTC offset.
|
||||
// Note that RFC3339_sec[] matches an ISO 8601 extended format for date and
|
||||
// time with UTC offset. Also note the use of "%Y": RFC3339 mandates that
|
||||
// years have exactly four digits, but we allow them to take their natural
|
||||
// width.
|
||||
extern const char RFC3339_full[]; // %Y-%m-%dT%H:%M:%E*S%Ez
|
||||
extern const char RFC3339_sec[]; // %Y-%m-%dT%H:%M:%S%Ez
|
||||
|
||||
|
|
Loading…
Reference in a new issue