[pkg-d-commits] [ldc] 36/95: Support config files with UTF-8 BOM

Matthias Klumpp mak at moszumanska.debian.org
Thu Jul 13 20:53:58 UTC 2017


This is an automated email from the git hooks/post-receive script.

mak pushed a commit to annotated tag v1.3.0-beta1
in repository ldc.

commit fdea747fb1d59a803c74b42703754e49ddfdbd87
Author: Martin <noone at nowhere.com>
Date:   Sun Feb 26 14:56:39 2017 +0100

    Support config files with UTF-8 BOM
---
 driver/config.d | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/driver/config.d b/driver/config.d
index 42ccad7..ff5ce6c 100644
--- a/driver/config.d
+++ b/driver/config.d
@@ -114,9 +114,14 @@ Setting[] parseConfigFile(const(char)* filename)
 
     auto content = new char[fileLength];
     const numRead = fread(content.ptr, 1, fileLength, file);
-    content = content[0 .. numRead];
     fclose(file);
 
+    // skip UTF-8 BOM
+    int start = 0;
+    if (numRead >= 3 && content[0 .. 3] == "\xEF\xBB\xBF")
+        start = 3;
+    content = content[start .. numRead];
+
     auto parser = Parser(cast(string) content, dFilename);
     return parser.parseConfig();
 }
@@ -520,7 +525,7 @@ unittest
 {
     static void testScalar(string input, string expected)
     {
-        auto setting = new Parser(input).parseValue(null);
+        auto setting = Parser(input).parseValue(null);
         assert(setting.type == Setting.Type.scalar);
         assert((cast(ScalarSetting) setting).val == expected);
     }
@@ -532,13 +537,14 @@ unittest
                 " strings"`, "concatenated multiline strings");
     testScalar("`abc\n\\ //comment \"`",
                 "abc\n\\ //comment \"");
+    testScalar(`"Üņïčöđë"`, "Üņïčöđë");
 }
 
 unittest
 {
     static void testArray(string input, string[] expected)
     {
-        auto setting = new Parser(input).parseValue(null);
+        auto setting = Parser(input).parseValue(null);
         assert(setting.type == Setting.Type.array);
         assert((cast(ArraySetting) setting).vals == expected);
     }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-d/ldc.git



More information about the pkg-d-commits mailing list