@@ -60,7 +60,7 @@ string printCaseStatements(K, V)(TrieNode!(K,V) node, string indentString)
60
60
if (v.children.length > 0 )
61
61
{
62
62
caseStatement ~= indentString;
63
- caseStatement ~= " \t if (endIndex >= inputString.length )\n " ;
63
+ caseStatement ~= " \t if (isEoF( inputString, endIndex) )\n " ;
64
64
caseStatement ~= indentString;
65
65
caseStatement ~= " \t {\n " ;
66
66
caseStatement ~= indentString;
@@ -110,3 +110,28 @@ string generateCaseTrie(string[] args ...)
110
110
}
111
111
return printCaseStatements (t, " " );
112
112
}
113
+
114
+ /**
115
+ * Returns: true if index points to end of inputString, false otherwise
116
+ */
117
+ pure nothrow bool isEoF(S)(S inputString, size_t index)
118
+ {
119
+ // note: EoF is determined according to D specification
120
+ return index >= inputString.length
121
+ || inputString[index] == Character.NUL
122
+ || inputString[index] == Character.SUB ;
123
+ }
124
+
125
+ private :
126
+
127
+ // Unicode character literals
128
+ enum Character
129
+ {
130
+ // End of file (EoF)
131
+ NUL = ' \u0000 ' , // NUL character
132
+ SUB = ' \u001A ' , // Substitute character
133
+
134
+ // Line feed (EoL)
135
+ CR = ' \u000D ' , // CR character
136
+ LF = ' \u000A ' , // LF character
137
+ }
0 commit comments