Marshall: ping?
On Wed, Feb 3, 2016 at 5:08 PM, Hans Wennborg <h...@chromium.org> wrote: > I'm OK if Marshall is. > > Thanks, > Hans > > On Wed, Feb 3, 2016 at 4:59 PM, Duncan P. N. Exon Smith via > cfe-commits <cfe-commits@lists.llvm.org> wrote: >> Hans, do you mind merging this to the 3.8 branch? >> >> Marshall, do you agree this is okay to take? >> >>> On 2016-Feb-03, at 11:30, Duncan P. N. Exon Smith via cfe-commits >>> <cfe-commits@lists.llvm.org> wrote: >>> >>> Author: dexonsmith >>> Date: Wed Feb 3 13:30:20 2016 >>> New Revision: 259682 >>> >>> URL: http://llvm.org/viewvc/llvm-project?rev=259682&view=rev >>> Log: >>> re.results.form: Format out-of-range subexpression references as null >>> >>> Rather than crashing in match_results::format() when a reference to a >>> marked subexpression is out of range, format the subexpression as empty >>> (i.e., replace it with an empty string). Note that >>> match_results::operator[]() has a range-check and returns a null match >>> in this case, so this just re-uses that logic. >>> >>> Modified: >>> libcxx/trunk/include/regex >>> libcxx/trunk/test/std/re/re.results/re.results.form/form1.pass.cpp >>> >>> Modified: libcxx/trunk/include/regex >>> URL: >>> http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/regex?rev=259682&r1=259681&r2=259682&view=diff >>> ============================================================================== >>> --- libcxx/trunk/include/regex (original) >>> +++ libcxx/trunk/include/regex Wed Feb 3 13:30:20 2016 >>> @@ -5387,8 +5387,8 @@ match_results<_BidirectionalIterator, _A >>> if ('0' <= *__fmt_first && *__fmt_first <= '9') >>> { >>> size_t __i = *__fmt_first - '0'; >>> - __out = _VSTD::copy(__matches_[__i].first, >>> - __matches_[__i].second, __out); >>> + __out = _VSTD::copy((*this)[__i].first, >>> + (*this)[__i].second, __out); >>> } >>> else >>> { >>> @@ -5439,8 +5439,8 @@ match_results<_BidirectionalIterator, _A >>> ++__fmt_first; >>> __i = 10 * __i + *__fmt_first - '0'; >>> } >>> - __out = _VSTD::copy(__matches_[__i].first, >>> - __matches_[__i].second, __out); >>> + __out = _VSTD::copy((*this)[__i].first, >>> + (*this)[__i].second, __out); >>> } >>> else >>> { >>> >>> Modified: libcxx/trunk/test/std/re/re.results/re.results.form/form1.pass.cpp >>> URL: >>> http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.results/re.results.form/form1.pass.cpp?rev=259682&r1=259681&r2=259682&view=diff >>> ============================================================================== >>> --- libcxx/trunk/test/std/re/re.results/re.results.form/form1.pass.cpp >>> (original) >>> +++ libcxx/trunk/test/std/re/re.results/re.results.form/form1.pass.cpp Wed >>> Feb 3 13:30:20 2016 >>> @@ -38,6 +38,31 @@ int main() >>> { >>> std::match_results<const char*> m; >>> const char s[] = "abcdefghijk"; >>> + assert(std::regex_search(s, m, std::regex("cd((e)fg)hi", >>> + >>> std::regex_constants::nosubs))); >>> + >>> + char out[100] = {0}; >>> + const char fmt[] = "prefix: $`, match: $&, suffix: $', m[1]: $1, >>> m[2]: $2"; >>> + char* r = m.format(output_iterator<char*>(out), >>> + fmt, fmt + std::char_traits<char>::length(fmt)).base(); >>> + assert(r == out + 54); >>> + assert(std::string(out) == "prefix: ab, match: cdefghi, suffix: >>> jk, m[1]: , m[2]: "); >>> + } >>> + { >>> + std::match_results<const char*> m; >>> + const char s[] = "abcdefghijk"; >>> + assert(std::regex_search(s, m, std::regex("cdefghi"))); >>> + >>> + char out[100] = {0}; >>> + const char fmt[] = "prefix: $`, match: $&, suffix: $', m[1]: $1, >>> m[2]: $2"; >>> + char* r = m.format(output_iterator<char*>(out), >>> + fmt, fmt + std::char_traits<char>::length(fmt)).base(); >>> + assert(r == out + 54); >>> + assert(std::string(out) == "prefix: ab, match: cdefghi, suffix: >>> jk, m[1]: , m[2]: "); >>> + } >>> + { >>> + std::match_results<const char*> m; >>> + const char s[] = "abcdefghijk"; >>> assert(std::regex_search(s, m, std::regex("cd((e)fg)hi"))); >>> >>> char out[100] = {0}; >>> @@ -61,6 +86,33 @@ int main() >>> assert(r == out + 34); >>> assert(std::string(out) == "match: cdefghi, m[1]: efg, m[2]: e"); >>> } >>> + { >>> + std::match_results<const char*> m; >>> + const char s[] = "abcdefghijk"; >>> + assert(std::regex_search(s, m, std::regex("cd((e)fg)hi", >>> + >>> std::regex_constants::nosubs))); >>> + >>> + char out[100] = {0}; >>> + const char fmt[] = "match: &, m[1]: \\1, m[2]: \\2"; >>> + char* r = m.format(output_iterator<char*>(out), >>> + fmt, fmt + std::char_traits<char>::length(fmt), >>> + std::regex_constants::format_sed).base(); >>> + assert(r == out + 30); >>> + assert(std::string(out) == "match: cdefghi, m[1]: , m[2]: "); >>> + } >>> + { >>> + std::match_results<const char*> m; >>> + const char s[] = "abcdefghijk"; >>> + assert(std::regex_search(s, m, std::regex("cdefghi"))); >>> + >>> + char out[100] = {0}; >>> + const char fmt[] = "match: &, m[1]: \\1, m[2]: \\2"; >>> + char* r = m.format(output_iterator<char*>(out), >>> + fmt, fmt + std::char_traits<char>::length(fmt), >>> + std::regex_constants::format_sed).base(); >>> + assert(r == out + 30); >>> + assert(std::string(out) == "match: cdefghi, m[1]: , m[2]: "); >>> + } >>> >>> { >>> std::match_results<const wchar_t*> m; >>> >>> >>> _______________________________________________ >>> cfe-commits mailing list >>> cfe-commits@lists.llvm.org >>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits >> >> _______________________________________________ >> cfe-commits mailing list >> cfe-commits@lists.llvm.org >> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits