1
2
3
4
5
6
7
8
9
| def cp932_substr(source, max_length):
"""CP932での最大バイト数(max_length) を超えない文字数で丸める"""
if not source:
return ""
data = map(lambda i: len(i.encode("cp932")), source)
target = filter(lambda i: i <= max_length, accumulate(data))
count = len(list(target))
return source[:count]
|