Message251740
| Author | steven.daprano |
|---|---|
| Recipients | Arfrever, ezio.melotti, lemburg, martin.panter, ncoghlan, pitrou, r.david.murray, serhiy.storchaka, sjt, steven.daprano, vstinner |
| Date | 2015-09-28.02:23:56 |
| SpamBayes Score | -1.0 |
| Marked as misclassified | Yes |
| Message-id | <20150928022344.GL23642@ando.pearwood.info> |
| In-reply-to | <1443370664.91.0.0888069203759.issue18814@psf.upfronthosting.co.za> |
| Content | |
|---|---|
On Sun, Sep 27, 2015 at 04:17:45PM +0000, R. David Murray wrote:
>
> I also want "detect if there are any surrogates".
I think that's useful enough it should be a str method. Here's a
pure-Python implementation:
def is_surrogate(s):
return any(0xD800 <= ord(c) <= 0xDFFF for c in s)
The actual Flexible String Representation implementation can be even
more efficient. All-ASCII and all-Latin1 strings cannot possibly include
surrogates, so is_surrogate will be a constant-time operation.
(If we care about making this a constant-time operation for all
strings, the constructor could set a flag on the string object. Since
the constructor has to walk the string anyway, I don't think that will
cost much time-wise.) |
|
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2015-09-28 02:23:56 | steven.daprano | set | recipients: + steven.daprano, lemburg, ncoghlan, pitrou, vstinner, ezio.melotti, Arfrever, r.david.murray, sjt, martin.panter, serhiy.storchaka |
| 2015-09-28 02:23:56 | steven.daprano | link | issue18814 messages |
| 2015-09-28 02:23:56 | steven.daprano | create | |