summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2000-03-10 23:01:36 (GMT)
committerGuido van Rossum <guido@python.org>2000-03-10 23:01:36 (GMT)
commit5aa88f097f43ae8ebb648f6e1ca57f227a3adc93 (patch)
tree08542fe40e5d38e650615585cb250de3363fdeef
parent09095f3f61b5672a529a9c5d7e17bf3e307a0364 (diff)
downloadcpython-5aa88f097f43ae8ebb648f6e1ca57f227a3adc93.zip
cpython-5aa88f097f43ae8ebb648f6e1ca57f227a3adc93.tar.gz
cpython-5aa88f097f43ae8ebb648f6e1ca57f227a3adc93.tar.bz2
Marc-Andre Lemburg: support for Unicode string literals (u"...", ur"...").
-rw-r--r--Python/compile.c25
1 files changed, 22 insertions, 3 deletions
diff --git a/Python/compile.c b/Python/compile.c
index 37cdfc9..72848fa 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -875,8 +875,18 @@ parsestr(s)
int c;
int first = *s;
int quote = first;
- if (isalpha(quote) || quote == '_')
- quote = *++s;
+ int rawmode = 0;
+ 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 != '\"') {
PyErr_BadInternalCall();
return NULL;
@@ -895,8 +905,17 @@ parsestr(s)
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);
+ }
v = PyString_FromStringAndSize((char *)NULL, len);
p = buf = PyString_AsString(v);
end = s + len;