mirror of
https://github.com/dlang/phobos.git
synced 2025-05-04 17:11:26 +03:00
[trivial] fix code style
This commit is contained in:
parent
8410f983b4
commit
628c59bffd
1 changed files with 249 additions and 228 deletions
89
std/string.d
89
std/string.d
|
@ -417,7 +417,7 @@ ptrdiff_t indexOf(Char1, Char2)(const(Char1)[] s,
|
|||
else
|
||||
{
|
||||
balance = std.algorithm.find!
|
||||
((dchar a, dchar b){return std.uni.toLower(a) == std.uni.toLower(b);})
|
||||
((a, b) => std.uni.toLower(a) == std.uni.toLower(b))
|
||||
(s, sub);
|
||||
}
|
||||
return balance.empty ? -1 : balance.ptr - s.ptr;
|
||||
|
@ -619,7 +619,7 @@ ptrdiff_t lastIndexOf(Char1, Char2)(const(Char1)[] s,
|
|||
{
|
||||
for (size_t i = s.length; !s.empty;)
|
||||
{
|
||||
if(endsWith!((dchar a, dchar b) {return std.uni.toLower(a) == std.uni.toLower(b);})
|
||||
if (endsWith!((a, b) => std.uni.toLower(a) == std.uni.toLower(b))
|
||||
(s, sub))
|
||||
{
|
||||
return cast(ptrdiff_t)i - to!(const(Char1)[])(sub).length;
|
||||
|
@ -709,13 +709,18 @@ auto representation(Char)(Char[] s) pure nothrow
|
|||
alias TypeTuple!(ubyte, ushort, uint)[Char.sizeof / 2] U;
|
||||
|
||||
// const and immutable storage classes
|
||||
static if (is(Char == immutable)) alias immutable(U) T;
|
||||
else static if (is(Char == const)) alias const(U) T;
|
||||
else alias U T;
|
||||
static if (is(Char == immutable))
|
||||
alias T = immutable(U);
|
||||
else static if (is(Char == const))
|
||||
alias T = const(U);
|
||||
else
|
||||
alias T = U;
|
||||
|
||||
// shared storage class (because shared(const(T)) is possible)
|
||||
static if (is(Char == shared)) alias shared(T) ST;
|
||||
else alias T ST;
|
||||
static if (is(Char == shared))
|
||||
alias ST = shared(T);
|
||||
else
|
||||
alias ST = T;
|
||||
|
||||
return cast(ST[]) s;
|
||||
}
|
||||
|
@ -744,11 +749,11 @@ unittest
|
|||
alias Int = FieldTypeTuple!Type[1];
|
||||
enum immutable(Char)[] hello = "hello";
|
||||
|
||||
test!( immutable(Char) , immutable(Int) )(hello);
|
||||
test!( const(Char) , const(Int) )(hello);
|
||||
test!( immutable Char, immutable Int)(hello);
|
||||
test!( const Char, const Int)(hello);
|
||||
test!( Char, Int)(hello.dup);
|
||||
test!( shared(Char) , shared(Int) )(cast(shared) hello.dup);
|
||||
test!(const(shared(Char)), const(shared(Int)))(hello);
|
||||
test!( shared Char, shared Int)(cast(shared) hello.dup);
|
||||
test!(const shared Char, const shared Int)(hello);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -763,7 +768,8 @@ S toLower(S)(S s) @trusted pure
|
|||
{
|
||||
foreach (i, dchar cOuter; s)
|
||||
{
|
||||
if (!std.uni.isUpper(cOuter)) continue;
|
||||
if (!std.uni.isUpper(cOuter))
|
||||
continue;
|
||||
auto result = s[0.. i].dup;
|
||||
foreach (dchar c; s[i .. $])
|
||||
{
|
||||
|
@ -915,7 +921,8 @@ S toUpper(S)(S s) @trusted pure
|
|||
{
|
||||
foreach (i, dchar cOuter; s)
|
||||
{
|
||||
if (!std.uni.isLower(cOuter)) continue;
|
||||
if (!std.uni.isLower(cOuter))
|
||||
continue;
|
||||
auto result = s[0.. i].dup;
|
||||
foreach (dchar c; s[i .. $])
|
||||
{
|
||||
|
@ -1697,7 +1704,7 @@ S rightJustify(S)(S s, size_t width, dchar fillChar = ' ') @trusted
|
|||
if (len >= width)
|
||||
return s;
|
||||
|
||||
auto retval = new Unqual!(C)[width - len + s.length];
|
||||
auto retval = new Unqual!C[width - len + s.length];
|
||||
retval[0 .. $ - s.length] = cast(C)fillChar;
|
||||
retval[$ - s.length .. $] = s[];
|
||||
return cast(S)retval;
|
||||
|
@ -1732,7 +1739,7 @@ S center(S)(S s, size_t width, dchar fillChar = ' ') @trusted
|
|||
if (len >= width)
|
||||
return s;
|
||||
|
||||
auto retval = new Unqual!(C)[width - len + s.length];
|
||||
auto retval = new Unqual!C[width - len + s.length];
|
||||
immutable left = (retval.length - s.length) / 2;
|
||||
retval[0 .. left] = cast(C)fillChar;
|
||||
retval[left .. left + s.length] = s[];
|
||||
|
@ -1864,7 +1871,6 @@ unittest
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/++
|
||||
Replaces spaces in $(D s) with the optimal number of tabs.
|
||||
All spaces and tabs at the end of a line are removed.
|
||||
|
@ -2567,7 +2573,8 @@ bool inPattern(S)(dchar c, in S pattern) if (isSomeString!S)
|
|||
foreach (size_t i, dchar p; pattern)
|
||||
{
|
||||
if (p == '^' && i == 0)
|
||||
{ result = true;
|
||||
{
|
||||
result = true;
|
||||
if (i + 1 == pattern.length)
|
||||
return (c == p); // or should this be an error?
|
||||
}
|
||||
|
@ -2692,7 +2699,8 @@ S removechars(S)(S s, in S pattern) if (isSomeString!S)
|
|||
|
||||
foreach (size_t i, dchar c; s)
|
||||
{
|
||||
if (inPattern(c, pattern)){
|
||||
if (inPattern(c, pattern))
|
||||
{
|
||||
if (!changed)
|
||||
{
|
||||
changed = true;
|
||||
|
@ -2749,7 +2757,8 @@ S squeeze(S)(S s, in S pattern = null)
|
|||
{
|
||||
run = 1;
|
||||
if (changed)
|
||||
{ if (r is null)
|
||||
{
|
||||
if (r is null)
|
||||
r = s[0 .. lasti].dup;
|
||||
std.utf.encode(r, c);
|
||||
}
|
||||
|
@ -2761,7 +2770,8 @@ S squeeze(S)(S s, in S pattern = null)
|
|||
{
|
||||
run = 0;
|
||||
if (changed)
|
||||
{ if (r is null)
|
||||
{
|
||||
if (r is null)
|
||||
r = s[0 .. lasti].dup;
|
||||
std.utf.encode(r, c);
|
||||
}
|
||||
|
@ -3061,14 +3071,13 @@ unittest
|
|||
import std.algorithm;
|
||||
|
||||
// Complete list of test types; too slow to test'em all
|
||||
// alias TypeTuple!(char[], const(char)[], immutable(char)[],
|
||||
// alias TestTypes = TypeTuple!(
|
||||
// char[], const( char)[], immutable( char)[],
|
||||
// wchar[], const(wchar)[], immutable(wchar)[],
|
||||
// dchar[], const(dchar)[], immutable(dchar)[])
|
||||
// TestTypes;
|
||||
// dchar[], const(dchar)[], immutable(dchar)[]);
|
||||
|
||||
// Reduced list of test types
|
||||
alias TypeTuple!(char[], const(wchar)[], immutable(dchar)[])
|
||||
TestTypes;
|
||||
alias TestTypes = TypeTuple!(char[], const(wchar)[], immutable(dchar)[]);
|
||||
|
||||
foreach (S; TestTypes)
|
||||
{
|
||||
|
@ -3182,6 +3191,7 @@ bool isNumeric(const(char)[] s, in bool bAllowSep = false)
|
|||
// Check for the complex type, and if found
|
||||
// reset the flags for checking the 2nd number.
|
||||
else if (c == '+')
|
||||
{
|
||||
if (i > 0)
|
||||
{
|
||||
bDecimalPoint = false;
|
||||
|
@ -3191,7 +3201,7 @@ bool isNumeric(const(char)[] s, in bool bAllowSep = false)
|
|||
}
|
||||
else
|
||||
return false;
|
||||
|
||||
}
|
||||
// Allow only one exponent per number
|
||||
else if (c == 'e')
|
||||
{
|
||||
|
@ -3387,7 +3397,8 @@ body
|
|||
{
|
||||
}
|
||||
else
|
||||
{ lastc = lastc.init;
|
||||
{
|
||||
lastc = lastc.init;
|
||||
continue;
|
||||
}
|
||||
if (b == 0)
|
||||
|
@ -3424,7 +3435,8 @@ body
|
|||
}
|
||||
|
||||
unittest
|
||||
{ char[4] buffer;
|
||||
{
|
||||
char[4] buffer;
|
||||
|
||||
assert(soundex(null) == null);
|
||||
assert(soundex("") == null);
|
||||
|
@ -3516,22 +3528,27 @@ string[string] abbrev(string[] values)
|
|||
string lv;
|
||||
|
||||
for (size_t i = 0; i < values_length; i = nexti)
|
||||
{ string value = values[i];
|
||||
{
|
||||
string value = values[i];
|
||||
|
||||
// Skip dups
|
||||
for (nexti = i + 1; nexti < values_length; nexti++)
|
||||
{ nv = values[nexti];
|
||||
{
|
||||
nv = values[nexti];
|
||||
if (value != values[nexti])
|
||||
break;
|
||||
}
|
||||
|
||||
for (size_t j = 0; j < value.length; j += std.utf.stride(value, j))
|
||||
{ string v = value[0 .. j];
|
||||
{
|
||||
string v = value[0 .. j];
|
||||
|
||||
if ((nexti == values_length || j > nv.length || v != nv[0 .. j]) &&
|
||||
(lasti == values_length || j > lv.length || v != lv[0 .. j]))
|
||||
{
|
||||
result[v] = value;
|
||||
}
|
||||
}
|
||||
result[value] = value;
|
||||
lasti = i;
|
||||
lv = value;
|
||||
|
@ -3777,7 +3794,8 @@ S[] outdent(S)(S[] lines) if(isSomeString!S)
|
|||
// because this function throws upon inconsistent indentation.
|
||||
if (shortestIndent is null || indent.length < shortestIndent.length)
|
||||
{
|
||||
if (indent.empty) return lines;
|
||||
if (indent.empty)
|
||||
return lines;
|
||||
shortestIndent = indent;
|
||||
}
|
||||
}
|
||||
|
@ -3786,6 +3804,7 @@ S[] outdent(S)(S[] lines) if(isSomeString!S)
|
|||
foreach (i; 0..lines.length)
|
||||
{
|
||||
auto stripped = __ctfe? lines[i].ctfe_strip() : lines[i].strip();
|
||||
|
||||
if (stripped.empty)
|
||||
{
|
||||
// Do nothing
|
||||
|
@ -3796,8 +3815,10 @@ S[] outdent(S)(S[] lines) if(isSomeString!S)
|
|||
}
|
||||
else
|
||||
{
|
||||
if (__ctfe) assert(false, "outdent: Inconsistent indentation");
|
||||
else throw new StringException("outdent: Inconsistent indentation");
|
||||
if (__ctfe)
|
||||
assert(false, "outdent: Inconsistent indentation");
|
||||
else
|
||||
throw new StringException("outdent: Inconsistent indentation");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue