def _handle_capital_sigma(self, value, i): # U+03A3 is in the Final_Sigma context when, it is found like this: #\p{cased} \p{case-ignorable}* U+03A3 not(\p{case-ignorable}* \p{cased}) # where \p{xxx} is a character with property xxx. j = i - 1 final_sigma = False while j >= 0: ch = value[j] if unicodedb.iscaseignorable(ord(ch)): j -= 1 continue final_sigma = unicodedb.iscased(ord(ch)) break if final_sigma: j = i + 1 length = len(value) while j < length: ch = value[j] if unicodedb.iscaseignorable(ord(ch)): j += 1 continue final_sigma = not unicodedb.iscased(ord(ch)) break if final_sigma: return unichr(0x3C2) else: return unichr(0x3C3)
def unicode_title__Unicode(space, w_self): input = w_self._value if len(input) == 0: return w_self builder = UnicodeBuilder(len(input)) previous_is_cased = False for i in range(len(input)): unichar = ord(input[i]) if previous_is_cased: builder.append(unichr(unicodedb.tolower(unichar))) else: builder.append(unichr(unicodedb.totitle(unichar))) previous_is_cased = unicodedb.iscased(unichar) return W_UnicodeObject(builder.build())
def unicode_title__Unicode(space, w_self): input = w_self._value if len(input) == 0: return w_self result = [u'\0'] * len(input) previous_is_cased = False for i in range(len(input)): unichar = ord(input[i]) if previous_is_cased: result[i] = unichr(unicodedb.tolower(unichar)) else: result[i] = unichr(unicodedb.totitle(unichar)) previous_is_cased = unicodedb.iscased(unichar) return W_UnicodeObject(u''.join(result))
def unicode_title__RopeUnicode(space, w_self): input = w_self._node length = input.length() if length == 0: return w_self result = [u'\0'] * length iter = rope.ItemIterator(input) previous_is_cased = False for i in range(input.length()): unichar = iter.nextint() if previous_is_cased: result[i] = unichr(unicodedb.tolower(unichar)) else: result[i] = unichr(unicodedb.totitle(unichar)) previous_is_cased = unicodedb.iscased(unichar) return W_RopeUnicodeObject(rope.rope_from_unicharlist(result))
def _iscased(self, ch): return unicodedb.iscased(ord(ch))