Switch to side-by-side view
--- a/Allura/allura/lib/utils.py +++ b/Allura/allura/lib/utils.py @@ -132,6 +132,16 @@ if not results: break yield results page += 1 + +def lsub_utf8(s, n): + '''Useful for returning n bytes of a UTF-8 string, rather than characters''' + while len(s) > n: + k = n + while (ord(s[k]) & 0xc0) == 0x80: + k -= 1 + return s[:k] + return s + class AntiSpam(object): '''Helper class for bot-protecting forms'''