49 lines
No EOL
1.6 KiB
Python
49 lines
No EOL
1.6 KiB
Python
#+------------------------------------------------------------------+
|
|
#| Clase para registrar palabras claves replace y obtener val |
|
|
#+------------------------------------------------------------------+
|
|
class CCommondsVariables:
|
|
def __init__(self):
|
|
self.m_dict_vals: dict = {}
|
|
|
|
# Getter aqui quizas no tenga sentido por que igual todo es publico en py..
|
|
|
|
# Mismo alg que Workflows byleo
|
|
def Translate(self, res: str) -> str:
|
|
t: int = len(res)
|
|
k: int = 0
|
|
final_res: str = ""
|
|
|
|
while k < t:
|
|
# Si son espacios o caracteres < 33 (ASCII)
|
|
if ord(res[k]) < 33:
|
|
final_res += res[k]
|
|
k += 1
|
|
continue
|
|
|
|
# Buscar patrón ${{...}}
|
|
if k + 2 < t and res[k] == '$' and res[k+1] == '{' and res[k+2] == '{':
|
|
k += 3
|
|
start: int = k
|
|
|
|
# Buscar el final }}
|
|
while k + 1 < t:
|
|
if res[k] == '}' and res[k+1] == '}':
|
|
break
|
|
k += 1
|
|
|
|
# Extraer variable
|
|
temp: str = res[start:k] # substring
|
|
|
|
# Buscar en diccionario
|
|
if temp in self.m_dict_vals:
|
|
final_res += self.m_dict_vals[temp]
|
|
else:
|
|
final_res += "${{" + temp + "}}"
|
|
|
|
k += 2 # Saltar }}
|
|
else:
|
|
# Agregar carácter normal
|
|
final_res += res[k]
|
|
k += 1
|
|
|
|
return final_res |