@@ -60,7 +60,7 @@ string printCaseStatements(K, V)(TrieNode!(K,V) node, string indentString)
6060 if (v.children.length > 0 )
6161 {
6262 caseStatement ~= indentString;
63- caseStatement ~= " \t if (endIndex >= inputString.length )\n " ;
63+ caseStatement ~= " \t if (isEoF( inputString, endIndex) )\n " ;
6464 caseStatement ~= indentString;
6565 caseStatement ~= " \t {\n " ;
6666 caseStatement ~= indentString;
@@ -110,3 +110,28 @@ string generateCaseTrie(string[] args ...)
110110 }
111111 return printCaseStatements (t, " " );
112112}
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