From 368fec422dea37982a9577a953efad47c47db524 Mon Sep 17 00:00:00 2001 From: Tomas Musil Date: Tue, 27 Mar 2012 01:29:04 +0200 Subject: [PATCH 1/1] kosmeticke upravy Soubor ocesavac.py uveden v soulad s dobrymi mravy. --- ocesavac.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/ocesavac.py b/ocesavac.py index 31e49fb..e1d0f59 100644 --- a/ocesavac.py +++ b/ocesavac.py @@ -1,25 +1,29 @@ +"""Modul pro odstranovani diakritiky a zvlastnich znaku.""" import unicodedata ABECEDA = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' def deaccent(unistr): + """Vrati text bez akcentu. Pochybna metoda pouzivajici unicodedata.""" return ''.join(aChar for aChar in unicodedata.normalize('NFD', unistr) if not unicodedata.combining(aChar)) def ocesat(text, mezery=True): + """Odstrani z textu akcenty, zvlastni znaky nahradi mezerami, posloupnost + mezer jednou mezerou a prevede vsechna pismena na velka.""" text = deaccent(unicode(text)).upper() if mezery: pole = [' '] - lastWh = True - for c in text: - if c in ABECEDA: - pole.append(c) - lastWh = False - elif not lastWh: + last_white = True + for char in text: + if char in ABECEDA: + pole.append(char) + last_white = False + elif not last_white: pole.append(' ') - lastWh = True - if not lastWh: + last_white = True + if not last_white: pole.append(' ') return ''.join(pole) else: # bez mezer -- 2.4.2