File tree Expand file tree Collapse file tree 1 file changed +7
-0
lines changed Expand file tree Collapse file tree 1 file changed +7
-0
lines changed Original file line number Diff line number Diff line change @@ -156,6 +156,13 @@ std::string escape_non_alnum(const std::string &to_escape)
156
156
std::ostringstream escaped;
157
157
for (auto &ch : to_escape)
158
158
{
159
+ // `ch` may have a negative value in the case of utf-8 encodings of
160
+ // characters above unicode code point 127. The following line maps these
161
+ // negative values to positive values in the 128-255 range, using a
162
+ // `static_cast`. This is neccessary in order to avoid undefined behaviour
163
+ // in `isalnum`. The positive values are then stored in an integer using a
164
+ // widening initialisation so that the stream insertion operator prints them
165
+ // as numbers rather than characters.
159
166
const int uch{static_cast <unsigned char >(ch)};
160
167
if (ch == ' _' )
161
168
escaped << " __" ;
You can’t perform that action at this time.
0 commit comments