diff --git a/stl/inc/format b/stl/inc/format index 65b9145847a..bf09d0572f2 100644 --- a/stl/inc/format +++ b/stl/inc/format @@ -579,14 +579,15 @@ constexpr void _Parse_format_string(basic_string_view<_CharT> _Format_str, _Hand const _CharT* _OpeningCurl = _Begin; if (*_Begin != '{') { // we didn't start at an opening curl, find the next one - _OpeningCurl = _STD find(_Begin + 1, _End, '{'); + _OpeningCurl = _Find_unchecked(_Begin + 1, _End, '{'); for (;;) { const _CharT* _ClosingCurl = _Find_unchecked(_Begin, _OpeningCurl, '}'); - // In this case we didn't find either a closing curl or opening curl. + // In this case there are neither closing nor opening curls in [_Begin, _OpenCurl) // Write the whole thing out. if (_ClosingCurl == _OpeningCurl) { - return _Handler._On_text(_Begin, _OpeningCurl); + _Handler._On_text(_Begin, _OpeningCurl); + break; } // We know _ClosingCurl isn't past the end because // the above condition was not met. diff --git a/tests/std/tests/P0645R10_text_formatting_formatting/test.cpp b/tests/std/tests/P0645R10_text_formatting_formatting/test.cpp index 3c0f0d9173d..1c97b8de8ae 100644 --- a/tests/std/tests/P0645R10_text_formatting_formatting/test.cpp +++ b/tests/std/tests/P0645R10_text_formatting_formatting/test.cpp @@ -8,9 +8,72 @@ #include #include +using namespace std; + // TODO: fill in tests -template std::back_insert_iterator std::vformat_to(std::back_insert_iterator, - const std::locale&, std::string_view, std::format_args_t, char>); +template back_insert_iterator std::vformat_to( + back_insert_iterator, const locale&, string_view, format_args_t, char>); + + +int main() { + string output_string = ""; + + vformat_to(back_insert_iterator(output_string), locale::classic(), "f", make_format_args()); + assert(output_string == "f"); + + output_string.clear(); + vformat_to(back_insert_iterator(output_string), locale::classic(), "format", make_format_args()); + assert(output_string == "format"); + + // test escaped opening curls + output_string.clear(); + vformat_to(back_insert_iterator(output_string), locale::classic(), "{{", make_format_args()); + assert(output_string == "{"); + + output_string.clear(); + vformat_to(back_insert_iterator(output_string), locale::classic(), "{{{{", make_format_args()); + assert(output_string == "{{"); + + output_string.clear(); + vformat_to(back_insert_iterator(output_string), locale::classic(), "x{{", make_format_args()); + assert(output_string == "x{"); + + output_string.clear(); + vformat_to(back_insert_iterator(output_string), locale::classic(), "{{ {{", make_format_args()); + assert(output_string == "{ {"); + + output_string.clear(); + vformat_to(back_insert_iterator(output_string), locale::classic(), "x{{x", make_format_args()); + assert(output_string == "x{x"); + + output_string.clear(); + vformat_to(back_insert_iterator(output_string), locale::classic(), "{{x", make_format_args()); + assert(output_string == "{x"); + + // tests escaped closing curls + output_string.clear(); + vformat_to(back_insert_iterator(output_string), locale::classic(), "}}", make_format_args()); + assert(output_string == "}"); + + output_string.clear(); + vformat_to(back_insert_iterator(output_string), locale::classic(), "}}}}", make_format_args()); + assert(output_string == "}}"); + + output_string.clear(); + vformat_to(back_insert_iterator(output_string), locale::classic(), "x}}", make_format_args()); + assert(output_string == "x}"); + + output_string.clear(); + vformat_to(back_insert_iterator(output_string), locale::classic(), "}} }}", make_format_args()); + assert(output_string == "} }"); + + output_string.clear(); + vformat_to(back_insert_iterator(output_string), locale::classic(), "x}}x", make_format_args()); + assert(output_string == "x}x"); + output_string.clear(); + vformat_to(back_insert_iterator(output_string), locale::classic(), "}}x", make_format_args()); + assert(output_string == "}x"); -int main() {} + return 0; +}