Commit 5aa88f09 authored by Guido van Rossum's avatar Guido van Rossum

Marc-Andre Lemburg: support for Unicode string literals (u"...", ur"...").

parent 09095f3f
...@@ -875,8 +875,18 @@ parsestr(s) ...@@ -875,8 +875,18 @@ parsestr(s)
int c; int c;
int first = *s; int first = *s;
int quote = first; int quote = first;
if (isalpha(quote) || quote == '_') int rawmode = 0;
quote = *++s; int unicode = 0;
if (isalpha(quote) || quote == '_') {
if (quote == 'u' || quote == 'U') {
quote = *++s;
unicode = 1;
}
if (quote == 'r' || quote == 'R') {
quote = *++s;
rawmode = 1;
}
}
if (quote != '\'' && quote != '\"') { if (quote != '\'' && quote != '\"') {
PyErr_BadInternalCall(); PyErr_BadInternalCall();
return NULL; return NULL;
...@@ -895,8 +905,17 @@ parsestr(s) ...@@ -895,8 +905,17 @@ parsestr(s)
return NULL; return NULL;
} }
} }
if (first != quote || strchr(s, '\\') == NULL) if (unicode) {
if (rawmode)
return PyUnicode_DecodeRawUnicodeEscape(
s, len, NULL);
else
return PyUnicode_DecodeUnicodeEscape(
s, len, NULL);
}
else if (rawmode || strchr(s, '\\') == NULL) {
return PyString_FromStringAndSize(s, len); return PyString_FromStringAndSize(s, len);
}
v = PyString_FromStringAndSize((char *)NULL, len); v = PyString_FromStringAndSize((char *)NULL, len);
p = buf = PyString_AsString(v); p = buf = PyString_AsString(v);
end = s + len; end = s + len;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment