[Python-Dev] String methods... finally

Barry A. Warsaw bwarsaw at cnri.reston.va.us
Wed Jun 16 01:46:24 CEST 1999


>>>>> "Guido" == Guido van Rossum <guido at cnri.reston.va.us> writes:

    Guido> Should \uDDDD be added?

That'd be nice! :)

    Guido> In Java, \u has the additional funny property that it is
    Guido> recognized *everywhere* in the source code, not just in
    Guido> string literals, and I believe that this complicates the
    Guido> interpretation of things like "\\uffff" (is the \uffff
    Guido> interpreted before regular string \ processing happens?).

No.  JLS section 3.3 says[1]

    In addition to the processing implied by the grammar, for each raw
    input character that is a backslash \, input processing must
    consider how many other \ characters contiguously precede it,
    separating it from a non-\ character or the start of the input
    stream. If this number is even, then the \ is eligible to begin a
    Unicode escape; if the number is odd, then the \ is not eligible
    to begin a Unicode escape.

and this is born out by example.

-------------------- snip snip --------------------Uni.java
public class Uni 
{
    static public void main(String[] args) {
        System.out.println("\\u00a9");
        System.out.println("\u00a9");
    }
}
-------------------- snip snip --------------------outputs
\u00a9
©
-------------------- snip snip --------------------

-Barry

[1] http://java.sun.com/docs/books/jls/html/3.doc.html#44591

PS. it is wonderful having the JLS online :)




More information about the Python-Dev mailing list