[Python-checkins] CVS: python/dist/src/Python compile.c,2.99,2.100

Guido van Rossum guido@cnri.reston.va.us
Fri, 10 Mar 2000 18:01:39 -0500 (EST)


Update of /projects/cvsroot/python/dist/src/Python
In directory eric:/home/guido/hp/mal/py-patched/Python

Modified Files:
	compile.c 
Log Message:
Marc-Andre Lemburg: support for Unicode string literals (u"...", ur"...").


Index: compile.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Python/compile.c,v
retrieving revision 2.99
retrieving revision 2.100
diff -C2 -r2.99 -r2.100
*** compile.c	1999/12/20 20:40:12	2.99
--- compile.c	2000/03/10 23:01:36	2.100
***************
*** 876,881 ****
  	int first = *s;
  	int quote = first;
! 	if (isalpha(quote) || quote == '_')
! 		quote = *++s;
  	if (quote != '\'' && quote != '\"') {
  		PyErr_BadInternalCall();
--- 876,891 ----
  	int first = *s;
  	int quote = first;
! 	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();
***************
*** 896,901 ****
  		}
  	}
! 	if (first != quote || strchr(s, '\\') == NULL)
  		return PyString_FromStringAndSize(s, len);
  	v = PyString_FromStringAndSize((char *)NULL, len);
  	p = buf = PyString_AsString(v);
--- 906,920 ----
  		}
  	}
! 	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);