Move application logic out of the constructor.
This commit is contained in:
parent
4d264ac551
commit
b172b36b3d
|
@ -105,8 +105,6 @@ struct TokenFormatter(OutputRange)
|
||||||
this(const ubyte[] rawSource, const(Token)[] tokens, immutable short[] depths,
|
this(const ubyte[] rawSource, const(Token)[] tokens, immutable short[] depths,
|
||||||
OutputRange output, ASTInformation* astInformation, Config* config)
|
OutputRange output, ASTInformation* astInformation, Config* config)
|
||||||
{
|
{
|
||||||
import std.algorithm.searching : countUntil;
|
|
||||||
|
|
||||||
this.rawSource = rawSource;
|
this.rawSource = rawSource;
|
||||||
this.tokens = tokens;
|
this.tokens = tokens;
|
||||||
this.depths = depths;
|
this.depths = depths;
|
||||||
|
@ -127,18 +125,8 @@ struct TokenFormatter(OutputRange)
|
||||||
assert(false, "config.end_of_line was unspecified");
|
assert(false, "config.end_of_line was unspecified");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
assert (eol == eol._default); // Same as input.
|
assert (eol == eol._default);
|
||||||
// Intentional wraparound, -1 turns into uint.max when not found:
|
this.eolString = eolStringFromInput;
|
||||||
const firstCR = cast(uint) rawSource.countUntil("\r");
|
|
||||||
if (firstCR < cast(uint) rawSource.countUntil("\n"))
|
|
||||||
{
|
|
||||||
if (firstCR == rawSource.countUntil("\r\n"))
|
|
||||||
this.eolString = "\r\n";
|
|
||||||
else
|
|
||||||
this.eolString = "\r";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
this.eolString = "\n";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -218,6 +206,17 @@ private:
|
||||||
/// and paren indentation is ignored.line breaks and "[" reset the counter.
|
/// and paren indentation is ignored.line breaks and "[" reset the counter.
|
||||||
int parenDepthOnLine;
|
int parenDepthOnLine;
|
||||||
|
|
||||||
|
string eolStringFromInput() const
|
||||||
|
{
|
||||||
|
import std.algorithm : countUntil;
|
||||||
|
|
||||||
|
// Intentional wraparound, -1 turns into uint.max when not found:
|
||||||
|
const firstCR = cast(uint) rawSource.countUntil("\r");
|
||||||
|
if (firstCR < cast(uint) rawSource.countUntil("\n"))
|
||||||
|
return firstCR == rawSource.countUntil("\r\n") ? "\r\n" : "\r";
|
||||||
|
return "\n";
|
||||||
|
}
|
||||||
|
|
||||||
void formatStep()
|
void formatStep()
|
||||||
{
|
{
|
||||||
import std.range : assumeSorted;
|
import std.range : assumeSorted;
|
||||||
|
|
Loading…
Reference in New Issue