Skip to content

Commit f17e363

Browse files
burblebeetkoeppe
authored andcommitted
P2845R8 Formatting of std::filesystem::path
Editorial changes: * Used Oxford commas, and added commas to help the parsing of longer sentences. * Named the sections "formatter support" for consistency. * Used "fmtr" instead of "fmt" in section names to avoid confusion with existing section names. * Moved the grammar for path-format-spec into the "general" section, and add an introductory half-sentence.
1 parent ca6a3f1 commit f17e363

File tree

2 files changed

+101
-1
lines changed

2 files changed

+101
-1
lines changed

source/iostreams.tex

Lines changed: 100 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13456,8 +13456,11 @@
1345613456
path weakly_canonical(const path& p, error_code& ec);
1345713457
}
1345813458

13459-
// \ref{fs.path.hash}, hash support
1346013459
namespace std {
13460+
// \ref{fs.path.fmtr}, formatting support
13461+
template<class charT> struct formatter<filesystem::path, charT>;
13462+
13463+
// \ref{fs.path.hash}, hash support
1346113464
template<class T> struct hash;
1346213465
template<> struct hash<filesystem::path>;
1346313466
}
@@ -15412,6 +15415,102 @@
1541215415
Equivalent to: \tcode{return path(lhs) /= rhs;}
1541315416
\end{itemdescr}
1541415417

15418+
\rSec3[fs.path.fmtr]{Formatting support}
15419+
15420+
\rSec4[fs.path.fmtr.general]{Formatting support overview}
15421+
15422+
\indexlibraryglobal{formatter}%
15423+
\begin{codeblock}
15424+
namespace std {
15425+
template<class charT> struct formatter<filesystem::path, charT> {
15426+
constexpr void set_debug_format();
15427+
15428+
constexpr typename basic_format_parse_context<charT>::iterator
15429+
parse(basic_format_parse_context<charT>& ctx);
15430+
15431+
template<class FormatContext>
15432+
typename FormatContext::iterator
15433+
format(const filesystem::path& path, FormatContext& ctx) const;
15434+
};
15435+
}
15436+
\end{codeblock}
15437+
15438+
\pnum
15439+
Formatting of paths uses formatting specifiers of the form
15440+
\begin{ncbnf}
15441+
\nontermdef{path-format-spec}\br
15442+
\opt{fill-and-align} \opt{width} \opt{\terminal{?}} \opt{\terminal{g}}
15443+
\end{ncbnf}
15444+
where the productions \fmtgrammarterm{fill-and-align} and \fmtgrammarterm{width}
15445+
are described in \ref{format.string}.
15446+
If the \tcode{?} option is used then
15447+
the path is formatted as an escaped string\iref{format.string.escaped}.
15448+
15449+
\rSec4[fs.path.fmtr.funcs]{Formatting support functions}
15450+
15451+
\indexlibrarymember{formatter}{set_debug_format}%
15452+
\begin{itemdecl}
15453+
constexpr void set_debug_format();
15454+
\end{itemdecl}
15455+
15456+
\begin{itemdescr}
15457+
\pnum
15458+
\effects
15459+
Modifies the state of the \tcode{formatter} to be as if
15460+
the \fmtgrammarterm{path-format-spec} parsed by the last call to \tcode{parse}
15461+
contained the \tcode{?} option.
15462+
\end{itemdescr}
15463+
15464+
\indexlibrarymember{formatter}{basic_format_parse_context}%
15465+
\begin{itemdecl}
15466+
constexpr typename basic_format_parse_context<charT>::iterator
15467+
parse(basic_format_parse_context<charT>& ctx);
15468+
\end{itemdecl}
15469+
15470+
\begin{itemdescr}
15471+
\pnum
15472+
\effects
15473+
Parses the format specifier as a \fmtgrammarterm{path-format-spec} and
15474+
stores the parsed specifiers in \tcode{*this}.
15475+
15476+
\pnum
15477+
\returns
15478+
An iterator past the end of the \fmtgrammarterm{path-format-spec}.
15479+
\end{itemdescr}
15480+
15481+
\indexlibrarymember{formatter}{format}%
15482+
\begin{itemdecl}
15483+
template<class FormatContext>
15484+
typename FormatContext::iterator
15485+
format(const filesystem::path& p, FormatContext& ctx) const;
15486+
\end{itemdecl}
15487+
15488+
\begin{itemdescr}
15489+
\pnum
15490+
\effects
15491+
Let \tcode{s} be \tcode{p.generic_string<filesystem::path::value_type>()}
15492+
if the \tcode{g} option is used,
15493+
otherwise \tcode{p.native()}.
15494+
Writes \tcode{s} into \tcode{ctx.out()},
15495+
adjusted according to the \fmtgrammarterm{path-format-spec}.
15496+
If \tcode{charT} is \keyword{char},
15497+
\tcode{path::value_type} is \keyword{wchar_t}, and
15498+
the literal encoding is UTF-8,
15499+
then the escaped path is transcoded from the native encoding for
15500+
wide character strings to UTF-8 with
15501+
maximal subparts of ill-formed subsequences
15502+
substituted with \ucode{fffd} \uname{replacement character}
15503+
per the Unicode Standard, Chapter 3.9 \ucode{fffd} Substitution in Conversion.
15504+
If \tcode{charT} and \tcode{path::value_type} are the same
15505+
then no transcoding is performed.
15506+
Otherwise, transcoding is
15507+
\impldef{transcoding of the escaped path when \tcode{charT} and \tcode{path::value_type} differ}.
15508+
15509+
\pnum
15510+
\returns
15511+
An iterator past the end of the output range.
15512+
\end{itemdescr}
15513+
1541515514
\rSec3[fs.path.hash]{Hash support}
1541615515

1541715516
\begin{itemdecl}

source/support.tex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,7 @@
634634
#define @\defnlibxname{cpp_lib_flat_set}@ 202207L // also in \libheader{flat_set}
635635
#define @\defnlibxname{cpp_lib_format}@ 202311L // also in \libheader{format}
636636
#define @\defnlibxname{cpp_lib_format_ranges}@ 202207L // also in \libheader{format}
637+
#define @\defnlibxname{cpp_lib_format_path}@ 202403L // also in \libheader{filesystem}
637638
#define @\defnlibxname{cpp_lib_format_uchar}@ 202311L // also in \libheader{format}
638639
#define @\defnlibxname{cpp_lib_formatters}@ 202302L // also in \libheader{stacktrace}, \libheader{thread}
639640
#define @\defnlibxname{cpp_lib_forward_like}@ 202207L // freestanding, also in \libheader{utility}

0 commit comments

Comments
 (0)