From dfde9c2b20339376369dcac9cf91772e840d0949 Mon Sep 17 00:00:00 2001 From: arookas Date: Sun, 13 Dec 2015 00:55:05 -0500 Subject: [PATCH] Fixed: account for full-width characters in error-line preview. --- frontend/main.cs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/frontend/main.cs b/frontend/main.cs index 31b2ad5..95f6209 100644 --- a/frontend/main.cs +++ b/frontend/main.cs @@ -149,10 +149,18 @@ namespace arookas sb.AppendLine(preview); for (var column = 1; column < location.Column; ++column) { - switch (preview[column - 1]) + var c = preview[column - 1]; + if (IsFullWidth(c)) { - case '\t': sb.Append('\t'); break; - default: sb.Append(" "); break; + sb.Append(" "); // full-width hack + } + else if (c == '\t') + { + sb.Append('\t'); + } + else + { + sb.Append(" "); } } sb.Append("^"); @@ -160,6 +168,10 @@ namespace arookas return sb.ToString(); } } + static bool IsFullWidth(char c) + { + return (c >= 0x2E80 && c <= 0x9FFF) || (c >= 0xFF00 && c <= 0xFFEF); + } static void Message(string format, params object[] args) { Console.Write(format, args); } static void Warning(string format, params object[] args)