Добавлена новая функция профилей case изменение регистра переменной

git-svn-id: http://svn.calculate.ru/calculate2/calculate-lib/trunk@926 c91db197-33c1-4113-bf15-f8a5c547ca64
develop
asamoukin 15 years ago
parent 6afd007ef6
commit dc52077257

@ -2064,7 +2064,7 @@ class utfBin:
resS = reVar.search(textProfileTmp)
return textProfileTmp
class profile(_file, _terms):
class profile(_file, _terms,xmlShare):
"""Класс для работы с профилями
На вход 2 параметра: объект хранения переменных, имя сервиса - не
@ -2371,6 +2371,49 @@ class profile(_file, _terms):
textProfileTmp[resS.end():]
return textProfileTmp
def funcCase(funTxt,resS,textProfileTmp):
"""локальная функция выдает переменную в определенном регистре
первый аргумент:
'uc' - верхний регистр,
'lc' - нижний регистр,
'ucfirst' - первая буква в верхнем регистре
второй аргумент:
название переменной
"""
terms = funTxt[5:-1].replace(" ","").split(",")
if not terms[0].strip() or\
(len(terms)==2 and not terms[1].strip()) or len(terms)!=2:
print _("error in profile %s")%nameProfile
print _("error profile term %s")%str(funTxt)
exit(1)
fArgvNames = ['uc','lc','ucfirst']
if not terms[0] in fArgvNames:
print _("error in profile %s")%nameProfile
print _("error profile term %s")%str(funTxt)
print _("first argument function is not 'uc' or 'lc' or\
'ucfirst'")
exit(1)
try:
strValue = str(self.objVar.Get(terms[1]))
except:
print _("error in profile %s")%nameProfile
print _("error var %s not found")%str(terms[1])
exit(1)
replace = ""
strValue = self._toUNICODE(strValue)
if terms[0] == 'uc':
replace = strValue.upper()
elif terms[0] == 'lc':
replace = strValue.lower()
elif terms[0] == 'ucfirst':
replace = strValue.capitalize()
if replace:
replace = replace.encode("UTF-8")
textProfileTmp = textProfileTmp[:resS.start()] + replace +\
textProfileTmp[resS.end():]
return textProfileTmp
# Локальные переменные
localVars = {}
# Локальные переменные для функции load
@ -2398,6 +2441,9 @@ class profile(_file, _terms):
elif funTxt[:4] == "rnd(":
textProfileTmp = funcRnd(funTxt,resS,textProfileTmp)
resS = self._reFunc.search(textProfileTmp)
elif funTxt[:5] == "case(":
textProfileTmp = funcCase(funTxt,resS,textProfileTmp)
resS = self._reFunc.search(textProfileTmp)
else:
resS = False
return textProfileTmp

Loading…
Cancel
Save