diff -Ncr COREBlog/utility.py COREBlog.fix/utility.py *** COREBlog/utility.py 2004-01-14 19:41:37.000000000 +0900 --- COREBlog.fix/utility.py 2004-02-26 21:02:05.000000000 +0900 *************** *** 610,642 **** 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(s,length,codestr): # return string in certain range(consider Japanese 2byte codes). ret_str = s ! print codestr == code_utf8 ! if len(s) > length: ! if codestr == code_euc: if is_euc_1(s,length) == 1: length = length - 1 ret_str = s[:length] ! elif codestr == code_sjis: ! if is_sjis_1(s,length+1): ! length = length - 1 ! ret_str = str[:length] ! elif codestr == code_utf8: ! ret_str = s[:length] ! else: ret_str = s[:length] return ret_str #Empty class for initializing ZCTextIndex ! class EmptyClass: pass \ ファイル末尾に改行がありません --- 610,678 ---- 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(s,length,codestr): # return string in certain range(consider Japanese 2byte codes). ret_str = s ! if codestr == code_euc: ! if len(s) > length: if is_euc_1(s,length) == 1: length = length - 1 ret_str = s[:length] ! elif codestr == code_sjis: ! if len(s) > length: ! length = length_in_sjis(s, length) ret_str = s[:length] + elif codestr == code_utf8: + length = length_in_utf8(s, length) + ret_str = s[:length] + elif len(s) > length: + ret_str = s[:length] return ret_str #Empty class for initializing ZCTextIndex ! class EmptyClass: pass