Revision 4113
Added by Aaron Marcuse-Kubitza over 12 years ago
strings.py | ||
---|---|---|
17 | 17 |
##### Parsing |
18 | 18 |
|
19 | 19 |
def concat(str0, str1, max_len): |
20 |
str0, str1 = map(to_raw_str, [str0, str1]) |
|
21 |
return to_unicode(str0[:max_len-len(str1)]+str1) |
|
20 |
# Use to_unicode so that substring does not split Unicode characters |
|
21 |
str0, str1 = map(to_unicode, [str0, str1]) |
|
22 |
# Use to_raw_str() because Unicode characters can be multi-byte, and length |
|
23 |
# limits often apply to the byte length, not the character length. |
|
24 |
return str0[:max_len-len(to_raw_str(str1))]+str1 |
|
22 | 25 |
|
23 | 26 |
def split(sep, str_): |
24 | 27 |
'''Returns [] if str_ == ""''' |
Also available in: Unified diff
strings.py: concat(): Perform substring operation on Unicode strings so that substring does not split Unicode characters. Still use to_raw_str() to calculate the str1 length because Unicode characters can be multi-byte, and length limits often apply to the byte length, not the character length.