mirror of
https://github.com/dlang/phobos.git
synced 2025-04-26 13:10:35 +03:00
This commit is contained in:
parent
530660bd9b
commit
205256abb1
2 changed files with 36 additions and 5 deletions
|
@ -127,14 +127,16 @@ if (is(Unqual!Char == Char))
|
||||||
|
|
||||||
Counting starts with `1`. Set to `0` if not used. Default: `0`.
|
Counting starts with `1`. Set to `0` if not used. Default: `0`.
|
||||||
*/
|
*/
|
||||||
ubyte indexStart;
|
ushort indexStart;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Index of the last argument for positional parameter ranges.
|
Index of the last argument for positional parameter ranges.
|
||||||
|
|
||||||
Counting starts with `1`. Set to `0` if not used. Default: `0`.
|
Counting starts with `1`. Set to `0` if not used. Default: `0`.
|
||||||
|
|
||||||
|
The maximum value of this field is used as a sentinel to indicate the arguments' length.
|
||||||
*/
|
*/
|
||||||
ubyte indexEnd;
|
ushort indexEnd;
|
||||||
|
|
||||||
version (StdDdoc)
|
version (StdDdoc)
|
||||||
{
|
{
|
||||||
|
@ -851,6 +853,18 @@ if (is(Unqual!Char == Char))
|
||||||
assert(f.indexStart == 0);
|
assert(f.indexStart == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://github.com/dlang/phobos/issues/10699
|
||||||
|
@safe pure unittest
|
||||||
|
{
|
||||||
|
import std.array : appender;
|
||||||
|
auto f = FormatSpec!char("%1:$d");
|
||||||
|
auto w = appender!(char[])();
|
||||||
|
|
||||||
|
f.writeUpToNextSpec(w);
|
||||||
|
assert(f.indexStart == 1);
|
||||||
|
assert(f.indexEnd == ushort.max);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Helper function that returns a `FormatSpec` for a single format specifier.
|
Helper function that returns a `FormatSpec` for a single format specifier.
|
||||||
|
|
||||||
|
|
|
@ -648,9 +648,16 @@ uint formattedWrite(Writer, Char, Args...)(auto ref Writer w, const scope Char[]
|
||||||
break SWITCH;
|
break SWITCH;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
throw new FormatException(
|
if (spec.indexEnd == spec.indexEnd.max)
|
||||||
text("Positional specifier %", spec.indexStart, '$', spec.spec,
|
break;
|
||||||
" index exceeds ", Args.length));
|
else if (spec.indexEnd == spec.indexStart)
|
||||||
|
throw new FormatException(
|
||||||
|
text("Positional specifier %", spec.indexStart, '$', spec.spec,
|
||||||
|
" index exceeds ", Args.length));
|
||||||
|
else
|
||||||
|
throw new FormatException(
|
||||||
|
text("Positional specifier %", spec.indexStart, ":", spec.indexEnd, '$', spec.spec,
|
||||||
|
" index exceeds ", Args.length));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return currentArg;
|
return currentArg;
|
||||||
|
@ -1199,6 +1206,16 @@ if (isSomeString!(typeof(fmt)))
|
||||||
formattedWrite(stream, "%s", aa);
|
formattedWrite(stream, "%s", aa);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://github.com/dlang/phobos/issues/10699
|
||||||
|
@safe pure unittest
|
||||||
|
{
|
||||||
|
import std.array : appender;
|
||||||
|
auto w = appender!(char[])();
|
||||||
|
|
||||||
|
formattedWrite(w, "%1:$d", 1, 2, 3);
|
||||||
|
assert(w.data == "123");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Formats a value of any type according to a format specifier and
|
Formats a value of any type according to a format specifier and
|
||||||
writes the result to an output range.
|
writes the result to an output range.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue