diff --git a/src/dfmt/formatter.d b/src/dfmt/formatter.d index d302f4a..8dcab2a 100644 --- a/src/dfmt/formatter.d +++ b/src/dfmt/formatter.d @@ -105,8 +105,6 @@ struct TokenFormatter(OutputRange) this(const ubyte[] rawSource, const(Token)[] tokens, immutable short[] depths, OutputRange output, ASTInformation* astInformation, Config* config) { - import std.algorithm.searching : countUntil; - this.rawSource = rawSource; this.tokens = tokens; this.depths = depths; @@ -127,18 +125,8 @@ struct TokenFormatter(OutputRange) assert(false, "config.end_of_line was unspecified"); else { - assert (eol == eol._default); // Same as input. - // Intentional wraparound, -1 turns into uint.max when not found: - 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"; + assert (eol == eol._default); + this.eolString = eolStringFromInput; } } } @@ -218,6 +206,17 @@ private: /// and paren indentation is ignored.line breaks and "[" reset the counter. 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() { import std.range : assumeSorted;