~milo/+junk/python-linaro

« back to all changes in this revision

Viewing changes to Objects/unicodeobject.c

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2012-03-09 23:23:55 UTC
  • mfrom: (36.1.11 sid)
  • Revision ID: package-import@ubuntu.com-20120309232355-syhmsoce7nubjxgl
Tags: 2.7.3~rc1-1ubuntu1
* Merge with Debian; remaining changes:
  - Build-depend on libdb5.1-dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1628
1628
                            *p++ = outCh;
1629
1629
#endif
1630
1630
                            surrogate = 0;
 
1631
                            continue;
1631
1632
                        }
1632
1633
                        else {
 
1634
                            *p++ = surrogate;
1633
1635
                            surrogate = 0;
1634
 
                            errmsg = "second surrogate missing";
1635
 
                            goto utf7Error;
1636
1636
                        }
1637
1637
                    }
1638
 
                    else if (outCh >= 0xD800 && outCh <= 0xDBFF) {
 
1638
                    if (outCh >= 0xD800 && outCh <= 0xDBFF) {
1639
1639
                        /* first surrogate */
1640
1640
                        surrogate = outCh;
1641
1641
                    }
1642
 
                    else if (outCh >= 0xDC00 && outCh <= 0xDFFF) {
1643
 
                        errmsg = "unexpected second surrogate";
1644
 
                        goto utf7Error;
1645
 
                    }
1646
1642
                    else {
1647
1643
                        *p++ = outCh;
1648
1644
                    }
1652
1648
                inShift = 0;
1653
1649
                s++;
1654
1650
                if (surrogate) {
1655
 
                    errmsg = "second surrogate missing at end of shift sequence";
1656
 
                    goto utf7Error;
 
1651
                    *p++ = surrogate;
 
1652
                    surrogate = 0;
1657
1653
                }
1658
1654
                if (base64bits > 0) { /* left-over bits */
1659
1655
                    if (base64bits >= 6) {
5164
5160
        }
5165
5161
        /* All other characters are considered unencodable */
5166
5162
        collstart = p;
5167
 
        collend = p+1;
5168
 
        while (collend < end) {
 
5163
        for (collend = p+1; collend < end; collend++) {
5169
5164
            if ((0 < *collend && *collend < 256) ||
5170
 
                !Py_UNICODE_ISSPACE(*collend) ||
5171
 
                Py_UNICODE_TODECIMAL(*collend))
 
5165
                Py_UNICODE_ISSPACE(*collend) ||
 
5166
                0 <= Py_UNICODE_TODECIMAL(*collend))
5172
5167
                break;
5173
5168
        }
5174
5169
        /* cache callback name lookup
5485
5480
 
5486
5481
    if (len == 0)
5487
5482
        return 0;
5488
 
    if (Py_UNICODE_ISLOWER(*s)) {
 
5483
    if (!Py_UNICODE_ISUPPER(*s)) {
5489
5484
        *s = Py_UNICODE_TOUPPER(*s);
5490
5485
        status = 1;
5491
5486
    }
5492
5487
    s++;
5493
5488
    while (--len > 0) {
5494
 
        if (Py_UNICODE_ISUPPER(*s)) {
 
5489
        if (!Py_UNICODE_ISLOWER(*s)) {
5495
5490
            *s = Py_UNICODE_TOLOWER(*s);
5496
5491
            status = 1;
5497
5492
        }
6369
6364
to the default encoding. errors may be given to set a different error\n\
6370
6365
handling scheme. Default is 'strict' meaning that encoding errors raise\n\
6371
6366
a UnicodeDecodeError. Other possible values are 'ignore' and 'replace'\n\
6372
 
as well as any other name registerd with codecs.register_error that is\n\
 
6367
as well as any other name registered with codecs.register_error that is\n\
6373
6368
able to handle UnicodeDecodeErrors.");
6374
6369
 
6375
6370
static PyObject *
6491
6486
             "S.find(sub [,start [,end]]) -> int\n\
6492
6487
\n\
6493
6488
Return the lowest index in S where substring sub is found,\n\
6494
 
such that sub is contained within s[start:end].  Optional\n\
 
6489
such that sub is contained within S[start:end].  Optional\n\
6495
6490
arguments start and end are interpreted as in slice notation.\n\
6496
6491
\n\
6497
6492
Return -1 on failure.");
6543
6538
    register Py_UNICODE *p;
6544
6539
    register long x;
6545
6540
 
 
6541
    assert(_Py_HashSecret_Initialized);
6546
6542
    if (self->hash != -1)
6547
6543
        return self->hash;
6548
6544
    len = PyUnicode_GET_SIZE(self);
 
6545
    /*
 
6546
      We make the hash of the empty string be 0, rather than using
 
6547
      (prefix ^ suffix), since this slightly obfuscates the hash secret
 
6548
    */
 
6549
    if (len == 0) {
 
6550
        self->hash = 0;
 
6551
        return 0;
 
6552
    }
6549
6553
    p = PyUnicode_AS_UNICODE(self);
6550
 
    x = *p << 7;
 
6554
    x = _Py_HashSecret.prefix;
 
6555
    x ^= *p << 7;
6551
6556
    while (--len >= 0)
6552
6557
        x = (1000003*x) ^ *p++;
6553
6558
    x ^= PyUnicode_GET_SIZE(self);
 
6559
    x ^= _Py_HashSecret.suffix;
6554
6560
    if (x == -1)
6555
6561
        x = -2;
6556
6562
    self->hash = x;
7226
7232
             "S.rfind(sub [,start [,end]]) -> int\n\
7227
7233
\n\
7228
7234
Return the highest index in S where substring sub is found,\n\
7229
 
such that sub is contained within s[start:end].  Optional\n\
 
7235
such that sub is contained within S[start:end].  Optional\n\
7230
7236
arguments start and end are interpreted as in slice notation.\n\
7231
7237
\n\
7232
7238
Return -1 on failure.");