~ubuntu-branches/ubuntu/lucid/python2.6/lucid

« back to all changes in this revision

Viewing changes to Objects/unicodeobject.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2010-03-11 13:30:19 UTC
  • mto: (10.1.13 sid)
  • mto: This revision was merged to the branch mainline in revision 44.
  • Revision ID: james.westby@ubuntu.com-20100311133019-sblbooa3uqrkoe70
Tags: upstream-2.6.5~rc2
ImportĀ upstreamĀ versionĀ 2.6.5~rc2

Show diffs side-by-side

added added

removed removed

Lines of Context:
6194
6194
 
6195
6195
/* This code should go into some future Unicode collation support
6196
6196
   module. The basic comparison should compare ordinals on a naive
6197
 
   basis (this is what Java does and thus JPython too). */
 
6197
   basis (this is what Java does and thus Jython too). */
6198
6198
 
6199
6199
/* speedy UTF-16 code point order comparison */
6200
6200
/* gleaned from: */
7036
7036
}
7037
7037
 
7038
7038
PyDoc_STRVAR(join__doc__,
7039
 
             "S.join(sequence) -> unicode\n\
 
7039
             "S.join(iterable) -> unicode\n\
7040
7040
\n\
7041
7041
Return a string which is the concatenation of the strings in the\n\
7042
 
sequence.  The separator between elements is S.");
 
7042
iterable.  The separator between elements is S.");
7043
7043
 
7044
7044
static PyObject*
7045
7045
unicode_join(PyObject *self, PyObject *data)
7603
7603
}
7604
7604
 
7605
7605
PyDoc_STRVAR(rpartition__doc__,
7606
 
             "S.rpartition(sep) -> (tail, sep, head)\n\
 
7606
             "S.rpartition(sep) -> (head, sep, tail)\n\
7607
7607
\n\
7608
7608
Search for the separator sep in S, starting at the end of S, and return\n\
7609
7609
the part before it, the separator itself, and the part after it.  If the\n\
8357
8357
           size_t buflen,
8358
8358
           PyObject *v)
8359
8359
{
 
8360
    PyObject *unistr;
 
8361
    char *str;
8360
8362
    /* presume that the buffer is at least 2 characters long */
8361
8363
    if (PyUnicode_Check(v)) {
8362
8364
        if (PyUnicode_GET_SIZE(v) != 1)
8367
8369
    else if (PyString_Check(v)) {
8368
8370
        if (PyString_GET_SIZE(v) != 1)
8369
8371
            goto onError;
8370
 
        buf[0] = (Py_UNICODE)PyString_AS_STRING(v)[0];
 
8372
        /* #7649: "u'%c' % char" should behave like "u'%s' % char" and fail
 
8373
           with a UnicodeDecodeError if 'char' is not decodable with the
 
8374
           default encoding (usually ASCII, but it might be something else) */
 
8375
        str = PyString_AS_STRING(v);
 
8376
        if ((unsigned char)str[0] > 0x7F) {
 
8377
            /* the char is not ASCII; try to decode the string using the
 
8378
               default encoding and return -1 to let the UnicodeDecodeError
 
8379
               be raised if the string can't be decoded */
 
8380
            unistr = PyUnicode_Decode(str, 1, NULL, "strict");
 
8381
            if (unistr == NULL)
 
8382
                return -1;
 
8383
            buf[0] = PyUnicode_AS_UNICODE(unistr)[0];
 
8384
            Py_DECREF(unistr);
 
8385
        }
 
8386
        else
 
8387
            buf[0] = (Py_UNICODE)str[0];
8371
8388
    }
8372
8389
 
8373
8390
    else {