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