Skip to content
This repository was archived by the owner on Oct 1, 2022. It is now read-only.

Commit fdfb5ca

Browse files
author
Stephan Dilly
committed
fix error when a key startet like another key fucking up the whole loca
1 parent c07d611 commit fdfb5ca

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

source/ask/locale.d

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,19 @@ string LocaParser(E, string input)()
5151
if (line.startsWith(enumMember))
5252
{
5353
auto lineArgs = line.split(",");
54-
auto locaKey = lineArgs[0];
55-
auto locaText = line[locaKey.length + 1 .. $].strip;
56-
auto entry = format("AlexaText(%s.%s, \"%s\"),", E.stringof, enumMember, locaText);
57-
res ~= entry ~ "\n";
58-
found = true;
59-
continue allMembers;
54+
55+
auto untilFirstComma = lineArgs[0];
56+
auto locaKey = untilFirstComma.strip;
57+
58+
if (locaKey == enumMember)
59+
{
60+
auto locaText = line[untilFirstComma.length + 1 .. $].strip;
61+
auto entry = format("AlexaText(%s.%s, \"%s\"),",
62+
E.stringof, enumMember, locaText);
63+
res ~= entry ~ "\n";
64+
found = true;
65+
continue allMembers;
66+
}
6067
}
6168
}
6269

@@ -85,3 +92,19 @@ unittest
8592
static assert(AlexaText_test[0].key == TextIds.key1);
8693
static assert(AlexaText_test[1].key == TextIds.key2);
8794
}
95+
96+
///
97+
unittest
98+
{
99+
enum TextIds
100+
{
101+
keyTitle,
102+
key,
103+
}
104+
105+
enum testCsv = "keyTitle, foo\n key, bar";
106+
107+
enum AlexaText[] AlexaText_test = mixin(LocaParser!(TextIds, testCsv));
108+
109+
static assert(AlexaText_test[1].text == "bar");
110+
}

0 commit comments

Comments
 (0)