From 3df6515755578ef33d097badcef77eba6c8d5bc6 Mon Sep 17 00:00:00 2001 From: Hackerpilot Date: Sat, 7 Mar 2015 23:15:37 -0800 Subject: [PATCH] Fix #58 --- src/dfmt.d | 18 +++++++++++++++++- tests/issue0058.d | 9 +++++++++ tests/issue0058.d.ref | 9 +++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 tests/issue0058.d create mode 100644 tests/issue0058.d.ref diff --git a/src/dfmt.d b/src/dfmt.d index ab087ac..f7c6d3d 100644 --- a/src/dfmt.d +++ b/src/dfmt.d @@ -1021,6 +1021,22 @@ private: return peekImplementation(tokenType, 0, ignoreComments); } + /// Bugs: not unicode correct + size_t tokenEndLine(const Token t) + { + import std.algorithm : count; + switch (t.type) + { + case tok!"comment": + case tok!"stringLiteral": + case tok!"wstringLiteral": + case tok!"dstringLiteral": + return t.line + (cast(ubyte[]) t.text).count('\n'); + default: + return t.line; + } + } + bool isBlockHeader(int i = 0) { if (i + index < 0 || i + index >= tokens.length) @@ -1039,7 +1055,7 @@ private: output.put("\n"); immutable bool hasCurrent = index + 1 < tokens.length; if (!justAddedExtraNewline && index > 0 - && hasCurrent && tokens[index].line - tokens[index - 1].line > 1) + && hasCurrent && tokens[index].line - tokenEndLine(tokens[index - 1]) > 1) { output.put("\n"); } diff --git a/tests/issue0058.d b/tests/issue0058.d new file mode 100644 index 0000000..547d359 --- /dev/null +++ b/tests/issue0058.d @@ -0,0 +1,9 @@ +/******************************************************** + * Helper function for checkAccess() + * Returns: + * false is not accessible + * true is accessible + */ +extern (C++) static bool isAccessible() +{ +} diff --git a/tests/issue0058.d.ref b/tests/issue0058.d.ref new file mode 100644 index 0000000..547d359 --- /dev/null +++ b/tests/issue0058.d.ref @@ -0,0 +1,9 @@ +/******************************************************** + * Helper function for checkAccess() + * Returns: + * false is not accessible + * true is accessible + */ +extern (C++) static bool isAccessible() +{ +}