Template talk:space as
From cppreference.com
Protected edit request: Support for leading/trailing spaces
Please change the code for this template from:
{{space|{{#len:{{{1|}}}}}}}<noinclude>
{{documentation | Template:space/doc}}
</noinclude>
to:
{{space|{{#expr:{{#len:_{{{1|}}}_}}-2}}}}<noinclude>
{{documentation | Template:space/doc}}
</noinclude>
This will enable the template to support strings containing leading and trailing spaces, or consisting entirely of spaces. Currently all spaces not between printable characters are ignored:
| Code | Output |
|---|---|
//{{space as|abcdefghi}}//
|
// //
|
//{{space as|a def i}}//
|
// //
|
//{{space as| def }}//
|
// //
|
//{{space as| }}//
|
////
|
With this change:
| Code | Output |
|---|---|
//{{space|{{#expr:{{#len:_abcdefghi_}}-2}}}}//
|
// //
|
//{{space|{{#expr:{{#len:_a def i_}}-2}}}}//
|
// //
|
//{{space|{{#expr:{{#len:_ def _}}-2}}}}//
|
// //
|
//{{space|{{#expr:{{#len:_ _}}-2}}}}//
|
// //
|
Thanks. -- FeRDNYC (talk) 17:45, 3 July 2021 (PDT)
- P.S> I don't believe this will change any of the existing template formatting. (AFAICT they don't rely on being able to insert ignored whitespaces.) However, it would open up some new formatting options.
- For example, Template:cpp/container/constructor_ord (Edited by --Space Mission (talk) 06:47, 12 July 2023 (PDT)) now contains code like:
{{dcl rev begin | num=2}}
{{dcl | since={{cpp/std|{{{1|}}}}} | 1=
template< class InputIt >
{{{1}}}( InputIt first, InputIt last,
{{space as|{{{1}}}}} const Compare& comp = Compare(),
{{space as|{{{1}}}}} const Allocator& alloc = Allocator() );
}}
{{dcl | since=c++14 | 1=
template< class InputIt >
{{{1}}}( InputIt first, InputIt last, const Allocator& alloc)
{{space as|{{{1}}}}} : {{{1}}}(first, last, Compare(), alloc) {}
}}
{{dcl rev end}}
- After this change, that could be written:
{{dcl rev begin | num=2}}
{{dcl | since={{cpp/std|{{{1|}}}}} | 1=
template< class InputIt >
{{{1}}}( InputIt first, InputIt last,
{{space as|{{{1}}}( }}const Compare& comp = Compare(),
{{space as|{{{1}}}( }}const Allocator& alloc = Allocator() );
}}
{{dcl | since=c++14 | 1=
template< class InputIt >
{{{1}}}( InputIt first, InputIt last, const Allocator& alloc)
{{space as|{{{1}}}(}}: {{{1}}}(first, last, Compare(), alloc) {}
}}
{{dcl rev end}}