diff -Ncr COREBlog.fix/utility.py COREBlog.fix2/utility.py *** COREBlog.fix/utility.py 2003-12-25 20:32:03.000000000 +0900 --- COREBlog.fix2/utility.py 2003-12-25 20:35:10.000000000 +0900 *************** *** 600,631 **** return ret ! def is_sjis_1(buff,pos): ! if (ord(buff[pos]) >= 0x81 and ord(buff[pos]) <= 0x9f) or \ ! (ord(buff[pos]) >= 0xe0 and ord(buff[pos]) <= 0xff): ! return 1 ! return 0 ! def get_string_part(str,length,codestr): # return string in certain range(consider Japanese 2byte codes). ret_str = str ! if len(str) > length: ! if codestr == code_euc: if is_euc_1(str,length) == 1: length = length - 1 ret_str = str[:length] ! elif codestr == code_sjis: ! if is_sjis_1(str,length+1): ! length = length - 1 ! ret_str = str[:length] ! elif codestr == code_utf8: ! ret_str = str[:length] ! else: ret_str = str[:length] return ret_str #Empty class for initializing ZCTextIndex class EmptyClass: pass --- 600,669 ---- return ret + def length_in_sjis(s, cols): + n = 0 + while n < cols: + c = ord(s[n]) + if c == 0x09 or c == 0x0a or c == 0x0d: + n += 1 + elif c >= 0x20 and c <= 0x7e: # alnum + n += 1 + elif c >= 0xa1 and c <= 0xdf: # kana + n += 1 + elif n + 1 >= cols: + break + elif (c >= 0x81 and c <= 0x9f) or (c >= 0xe0 and c <= 0xfc): + c = ord(s[n + 1]) + if (c >= 0x40 and c <= 0x7e) or (c >= 0x80 and c <= 0xfc): + n += 2 + else: + break + else: + break + return n ! def length_in_utf8(s, cols): ! size = len(s) ! cpos = 0 ! bytes = 0 ! while (cols > 0) and (cpos < size): ! c = ord(s[cpos]) ! if (c & 0x80) == 0: ! bytes = 1 ! cols -= 1 ! elif (c & 0xe0) == 0xc0: ! bytes = 2 ! cols -= 1 ! elif (c & 0xe0) == 0xe0: ! bytes = 3 ! cols -= 2 ! else: ! break ! cpos += bytes ! if (cols < 0) or (cpos > size): ! cpos -= bytes ! return cpos def get_string_part(str,length,codestr): # return string in certain range(consider Japanese 2byte codes). ret_str = str ! if codestr == code_euc: ! if len(str) > length: if is_euc_1(str,length) == 1: length = length - 1 ret_str = str[:length] ! elif codestr == code_sjis: ! if len(str) > length: ! length = length_in_sjis(str, length) ret_str = str[:length] + elif codestr == code_utf8: + length = length_in_utf8(str, length) + ret_str = str[:length] + elif len(str) > length: + ret_str = str[:length] return ret_str + #Empty class for initializing ZCTextIndex class EmptyClass: pass