################################################# # -*- coding: euc-jp -*- # require : JapaneseCodecs # from string import split, strip, count def checkByte(data, start, end): '''全角文字を調べる''' try: test = unicode(data[start:end]) return end except UnicodeError: return end - 1 def checkHynLast(line1, start, tempend): '''最後の文字をチェック''' len1 = len(line1) try: test = unicode(line1[len1 - 1:]) p = line1[len1 - 1:] for i in ('$','(','\',','[','{','£'): if p == i: tempend = tempend -1 tempend = tempend return tempend except UnicodeError: p = line1[len1 -2:] for i in ('‘','“','〈','《','「','『','【','〔','$','(','[','{','¥'): if p == i: tempend = tempend -2 tempend = tempend return tempend def checkHynFst(line1, line2, start, tempend): '''最初の文字をチェック''' len1 = len(line1) try: test = unicode(line2[:1]) p = line2[:1] for i in ('!','%',')',',','.',':',';','?',']','}'): if p == i: try: test = unicode(line1[len1 -1:]) tempend = tempend - 1 except UnicodeError: tempend = tempend - 2 return tempend except UnicodeError: p = line2[:2] for i in ('¢','°','’','”','‰','′','″','℃','、','。','々','〉',\ '》','」','』','】','〕','ぁ','ぃ','ぅ','ぇ','ぉ','っ','ゃ',\ 'ゅ','ょ','ゎ','゛','゜','ゝ','ゞ','ァ','ィ','ゥ','ェ','ォ',\ 'ッ','ャ','ュ','ョ','ヮ','ヵ','ヶ','・','ー','ヽ','ヾ','!',\ '%',')',',','.',':',';','?',']','}'): if p == i: try: test = unicode(line1[len1 - 1:]) return tempend - 1 except UnicodeError: return tempend - 2 return tempend def jformat(data, ketasu = 38): '''禁則処理''' keta = ketasu * 2 SplitText = split(data,"\n") f = '' for Text in SplitText: start = 0 end = keta while 1: tempend = checkByte(Text, start, end) line1 = Text[start:tempend] if not line1: break line2 = Text[tempend:] tempend = checkHynFst(line1, line2, start, tempend) tempend = checkHynLast(Text[start:tempend], start, tempend) line1 = Text[start:tempend] f = f + line1 + '\n' start = tempend end = tempend + keta print line1 return f