-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement the ?
format specifier for strings and characters
#3656
Implement the ?
format specifier for strings and characters
#3656
Conversation
4448022
to
cc9aabc
Compare
tools/unicode_properties_parse/grapheme_break_property_data_gen.py
Outdated
Show resolved
Hide resolved
#if _HAS_CXX23 | ||
case '?': | ||
_Cat = _Presentation_type_category::_Escape; | ||
break; | ||
#endif // _HAS_CXX23 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential future improvement:
We could recognize this in c++20 and earlier modes and emit a helpful diagnostic.
This comment was marked as resolved.
This comment was marked as resolved.
FYI @barcharcraz, changes have been pushed since your approval but they were minor so I don't think you need to take another look. |
I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed. |
Thanks for implementing this sub-feature, which is not questionable in any way! |
* This PR implements debug-enabled standard `formatter` specializations, * Drive-by: rename tests added in microsoft#3656 - use `text_formatting_` prefix instead of `formatting_ranges_` (for consistency), * Towards microsoft#2919.
* This PR implements debug-enabled standard `formatter` specializations, * Drive-by: rename tests added in microsoft#3656 - use `text_formatting_` prefix instead of `formatting_ranges_` (for consistency), * Towards microsoft#2919.
This implements [format.string.escaped], which is part of WG21-P2286R8 "Formatting Ranges" and modified by WG21-P2713R1 "Escaping Improvements In
std::format
". Works towards #2919.To implement this feature, two arrays,
__printable_ranges
and_Grapheme_Extend_ranges
, are added to__msvc_format_ucd_tables.hpp
.__printable_ranges
represents code points whoseGeneral_Category
is in the groupsL
,M
,N
,P
,S
(that is, code points that are not from categoriesZ
orC
), plus the ASCII space character.\u{hex-digit-sequence}
format. ([format.string.escaped]/(2.2.1.2.1))General_Category
, instead of this invented property. This requires more storage and a new data structure, though._Grapheme_Extend_ranges
represents code points with the Unicode propertyGrapheme_Extend=Yes
.Grapheme_Cluster_Break
:Grapheme_Extend=Yes
isGrapheme_Cluster_Break=Extend
minusEmoji_Modifier=Yes
, andEmoji_Modifier=Yes
is just1F3FB..1F3FF
. I chose to define a new array for simplicity.When the literal encoding is not UTF-8, UTF-16, or UTF-32, the set of "separator or non-printable characters" is implementation-defined. In this implementation, the set consists of all characters that correspond to non-printable Unicode code points (that is, code points outside of
__printable_ranges
, see above). If a character is non-printable, it is translated into\u{XXXX}
, whereXXXX
is the hex value of the Unicode code point (not the original value).If a code unit sequence cannot be converted to a Unicode scalar value, the
\x{XX}
escape sequence is used.