Text functions.
Funciones de nombre corto
Text Q(Text txtVal)Text W(Text txtVal)Text F(Anything anyVal)Funciones
Set Txt2Set(Text txtInp, Text sepTok)Set TxtTokenizer(Text txtInp, Text tagBrk)Text TxtBetween2Tag(Text inpTxt, Text tagIni, Text tagEnd, Real cmpFlg)Text TxtInside2TagPlus(Text txtInp, Text tagIni, Text tagEnd)Text TxtOutside2Tag(Text txtInp, Text tagIni, Text tagEnd)Text TxtOutHtmTag(Text htmTxt)Text TxtOutHtmScr(Text htmTxt)Text TxtReplaceSecuence(Text txtInp, Set repTab)//////////////////////////////////////////////////////////////////////////////
Text Q(Text txtVal) // Text
//////////////////////////////////////////////////////////////////////////////
{ Char(34) + txtVal + Char(34) };
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna un texto entre dobles comillas. Equivalente a la funcion Tol Qt().",
Q);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Text W(Text txtVal) // Text
//////////////////////////////////////////////////////////////////////////////
{ Replace(txtVal, "/", "\\") };
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna un camino en formato Unix convertido a formato Windows/DOS.",
W);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Text F(Anything anyVal)
//////////////////////////////////////////////////////////////////////////////
{
Text graVal = Grammar(anyVal);
Case
(
graVal=="Text", anyVal, // Ya es texto
graVal=="Real", If(EQ(anyVal, Round(anyVal)),
FormatReal(anyVal, "%.0lf"), // Entero sin decimales
FormatReal(anyVal, "%.2lf")), // 2 decimales
graVal=="Date", If(Hour(anyVal),
FormatDate(anyVal, "%c%Y/%m/%d %h:%i:%s"), // Tiempo
FormatDate(anyVal, "%c%Y/%m/%d")), // Fecha
graVal=="Set",
{
Real crdSet = Card(anyVal);
Case(
EQ(crdSet,0), "[]",
EQ(crdSet,1), "["+F(anyVal[1])+"]",
TRUE, "["+F(anyVal[1])+SetSum(For(2,crdSet,Text(Real setPos)
{ "|"+F(anyVal[setPos]) }))+"]")
},
TRUE, "Not basic type"
)
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna numeros, fechas, textos, conjuntos como un texto de formato simple.",
F);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Set Txt2Set(Text txtInp, // Texto de entrada
Text sepTok) // Elemento separador
//////////////////////////////////////////////////////////////////////////////
{
Set setSep = TxtTokenizer(txtInp, sepTok);
Set setCmp = EvalSet(setSep, Text(Text eleTxt) { Compact(eleTxt) });
setCmp
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna un conjunto a partir de un texto txtInp, troceandolo por un separador
sepTok y dependiendo de ctrFun puede, en este orde, si C compactar, si N
eliminar los texto nulos, si U retornar elementos unicos y si S retornar el
set ordenado.",
Txt2Set);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Set TxtTokenizer(Text txtInp, // Texto de entrada
Text tagBrk) // Tag por el que se corta
//////////////////////////////////////////////////////////////////////////////
{ Tokenizer(Replace(txtInp, tagBrk, Char(7)), Char(7)) };
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna un conjunto de textos resultado de cortar el texto de entrada por un
unico tag tagBrk no incluyendo el tag tagBrk dentro de los textos.
Se soporta en la funcion Tol Tokenizer() que rompe por un unico caracter.
Usa como caracter interno de corte el 7 (bell), esperando que no aparezca.",
TxtTokenizer);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Text TxtBetween2Tag(Text inpTxt, // Texto de entrada
Text tagIni, // Tag inicial
Text tagEnd, // Tag final
Real cmpFlg) // Si true aplica Compact()
//////////////////////////////////////////////////////////////////////////////
{
Real posIni = TextFind(inpTxt, tagIni);
Text result = If(LE(posIni,0), "",
{
Real lenIni = TextLength(tagIni);
Real posSub = posIni + lenIni;
Real posEnd = TextFind(inpTxt, tagEnd, posSub);
If(LE(posEnd, 0), "", Sub(inpTxt, posSub, posEnd-1))
});
If(cmpFlg, Compact(result), result)
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna un subtexto entre la primera ocurrencia de tagIni y tagEnd.
Si tagIni o tagEnd no aparecen retorna la tira vacia.
Si cmpFlg es cierto entonces aplica la funcion Compact() al texto que retorna.
Por ejemplo:
TxtBetween2Tag('a b [[ c ]] d [[ e ]] f', '[[', ']]', TRUE)
retorna 'c'.",
TxtBetween2Tag);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Text TxtInside2TagPlus(Text txtInp, // Input text
Text tagIni, // Initial tag
Text tagEnd) // End tag)
//////////////////////////////////////////////////////////////////////////////
{
Real posIni = TextFind(txtInp, tagIni);
If(LE(posIni,0), "",
{
Real lenIni = TextLength(tagIni);
Real posSub = posIni + lenIni;
Real posEnd = TextFind(txtInp, tagEnd, posSub);
Real txtLen = TextLength(txtInp);
If(And(EQ(posIni,1),LE(posEnd,0)), txtInp,
If(And(GT(posIni,1),LE(posEnd,0)), Sub(txtInp,posIni, txtLen),
Sub(txtInp,posIni,posEnd+TextLength(tagEnd)-1)+ // Recursion
TxtInside2TagPlus(Sub(txtInp, posEnd+TextLength(tagEnd), txtLen),
tagIni, tagEnd)))
})
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns all the texts between 2 tags plus theis tags (tagIni and tagEnd)
in txtInp.
Is diferente that the classic TxtInside2Tag().
For example: <aaa(::)bbb(---)ccc>, <(>, <)> -> <(::)(---)>.",
TxtInside2TagPlus);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Text TxtOutside2Tag(Text txtInp, // Input text
Text tagIni, // Initial tag
Text tagEnd) // End tag)
//////////////////////////////////////////////////////////////////////////////
{
Set txtSet = TxtTokenizer(tagIni + tagEnd + txtInp, tagIni);
Set txtCic = EvalSet(txtSet, Text(Text txtTok)
{ TxtBetween2Tag(txtTok + tagIni, tagEnd, tagIni, FALSE) });
SetSum(txtCic)
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns all the texts outside 2 tags (tagIni and tagEnd) in txt.
For example: <aaa(::)bbb(:::)ccc>, <(>, <)> -> <aaabbbccc>.",
TxtOutside2Tag);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Text TxtOutHtmTag(Text htmTxt)
//////////////////////////////////////////////////////////////////////////////
{ TxtOutside2Tag(htmTxt, "<", ">") };
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna todos el texto fuera de los tags de html.",
TxtOutHtmTag);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Text TxtOutHtmScr(Text htmTxt)
//////////////////////////////////////////////////////////////////////////////
{ TxtOutHtmTag(TxtOutside2Tag(htmTxt, "<script", "</script>")) };
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna todos el texto fuera de los tags de html y de los scripts.
Sirve para extraer texto limpio del que sacar palabras clave.",
TxtOutHtmScr);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Text TxtReplaceSecuence(Text txtInp, // Texto de entrada
Set repTab) // Tabla de reemplazamientos
//////////////////////////////////////////////////////////////////////////////
{
Real crdTab = Card(repTab); // Numero de cambios a realizar
If(!crdTab, txtInp, // Nada que hacer
{
Text txtNew = Replace(txtInp, repTab[1][1], repTab[1][2]); // Un cambio
TxtReplaceSecuence(txtNew, SetLastN(repTab,crdTab-1)) // Resto de cambios
})
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna un texto resultado de aplicar la tabla de reemplazamientos repTab al
texto de entrada txtIno.
Es una version de ReplaceTable(txtInp, repTab, 1) que garantiza la secuencia
de los reemplazamientos del primero al ultimo de los reemplazamientos.
Es una funcion recursiva.
Cada reemplazamiento solo se efectua una vez.",
TxtReplaceSecuence);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// FILE : txt.tol
// AUTHOR : http://www.asolver.com
// PURPOSE : Text functions.
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// SHORTNAMES
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Text Q(Text txtVal) // Text
//////////////////////////////////////////////////////////////////////////////
{ Char(34) + txtVal + Char(34) };
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna un texto entre dobles comillas. Equivalente a la funcion Tol Qt().",
Q);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Text W(Text txtVal) // Text
//////////////////////////////////////////////////////////////////////////////
{ Replace(txtVal, "/", "\\") };
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna un camino en formato Unix convertido a formato Windows/DOS.",
W);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Text F(Anything anyVal)
//////////////////////////////////////////////////////////////////////////////
{
Text graVal = Grammar(anyVal);
Case
(
graVal=="Text", anyVal, // Ya es texto
graVal=="Real", If(EQ(anyVal, Round(anyVal)),
FormatReal(anyVal, "%.0lf"), // Entero sin decimales
FormatReal(anyVal, "%.2lf")), // 2 decimales
graVal=="Date", If(Hour(anyVal),
FormatDate(anyVal, "%c%Y/%m/%d %h:%i:%s"), // Tiempo
FormatDate(anyVal, "%c%Y/%m/%d")), // Fecha
graVal=="Set",
{
Real crdSet = Card(anyVal);
Case(
EQ(crdSet,0), "[]",
EQ(crdSet,1), "["+F(anyVal[1])+"]",
TRUE, "["+F(anyVal[1])+SetSum(For(2,crdSet,Text(Real setPos)
{ "|"+F(anyVal[setPos]) }))+"]")
},
TRUE, "Not basic type"
)
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna numeros, fechas, textos, conjuntos como un texto de formato simple.",
F);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// FUNCTIONS
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Set Txt2Set(Text txtInp, // Texto de entrada
Text sepTok) // Elemento separador
//////////////////////////////////////////////////////////////////////////////
{
Set setSep = TxtTokenizer(txtInp, sepTok);
Set setCmp = EvalSet(setSep, Text(Text eleTxt) { Compact(eleTxt) });
setCmp
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna un conjunto a partir de un texto txtInp, troceandolo por un separador
sepTok y dependiendo de ctrFun puede, en este orde, si C compactar, si N
eliminar los texto nulos, si U retornar elementos unicos y si S retornar el
set ordenado.",
Txt2Set);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Set TxtTokenizer(Text txtInp, // Texto de entrada
Text tagBrk) // Tag por el que se corta
//////////////////////////////////////////////////////////////////////////////
{ Tokenizer(Replace(txtInp, tagBrk, Char(7)), Char(7)) };
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna un conjunto de textos resultado de cortar el texto de entrada por un
unico tag tagBrk no incluyendo el tag tagBrk dentro de los textos.
Se soporta en la funcion Tol Tokenizer() que rompe por un unico caracter.
Usa como caracter interno de corte el 7 (bell), esperando que no aparezca.",
TxtTokenizer);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Text TxtBetween2Tag(Text inpTxt, // Texto de entrada
Text tagIni, // Tag inicial
Text tagEnd, // Tag final
Real cmpFlg) // Si true aplica Compact()
//////////////////////////////////////////////////////////////////////////////
{
Real posIni = TextFind(inpTxt, tagIni);
Text result = If(LE(posIni,0), "",
{
Real lenIni = TextLength(tagIni);
Real posSub = posIni + lenIni;
Real posEnd = TextFind(inpTxt, tagEnd, posSub);
If(LE(posEnd, 0), "", Sub(inpTxt, posSub, posEnd-1))
});
If(cmpFlg, Compact(result), result)
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna un subtexto entre la primera ocurrencia de tagIni y tagEnd.
Si tagIni o tagEnd no aparecen retorna la tira vacia.
Si cmpFlg es cierto entonces aplica la funcion Compact() al texto que retorna.
Por ejemplo:
TxtBetween2Tag('a b [[ c ]] d [[ e ]] f', '[[', ']]', TRUE)
retorna 'c'.",
TxtBetween2Tag);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Text TxtInside2TagPlus(Text txtInp, // Input text
Text tagIni, // Initial tag
Text tagEnd) // End tag)
//////////////////////////////////////////////////////////////////////////////
{
Real posIni = TextFind(txtInp, tagIni);
If(LE(posIni,0), "",
{
Real lenIni = TextLength(tagIni);
Real posSub = posIni + lenIni;
Real posEnd = TextFind(txtInp, tagEnd, posSub);
Real txtLen = TextLength(txtInp);
If(And(EQ(posIni,1),LE(posEnd,0)), txtInp,
If(And(GT(posIni,1),LE(posEnd,0)), Sub(txtInp,posIni, txtLen),
Sub(txtInp,posIni,posEnd+TextLength(tagEnd)-1)+ // Recursion
TxtInside2TagPlus(Sub(txtInp, posEnd+TextLength(tagEnd), txtLen),
tagIni, tagEnd)))
})
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns all the texts between 2 tags plus theis tags (tagIni and tagEnd)
in txtInp.
Is diferente that the classic TxtInside2Tag().
For example: <aaa(::)bbb(---)ccc>, <(>, <)> -> <(::)(---)>.",
TxtInside2TagPlus);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Text TxtOutside2Tag(Text txtInp, // Input text
Text tagIni, // Initial tag
Text tagEnd) // End tag)
//////////////////////////////////////////////////////////////////////////////
{
Set txtSet = TxtTokenizer(tagIni + tagEnd + txtInp, tagIni);
Set txtCic = EvalSet(txtSet, Text(Text txtTok)
{ TxtBetween2Tag(txtTok + tagIni, tagEnd, tagIni, FALSE) });
SetSum(txtCic)
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns all the texts outside 2 tags (tagIni and tagEnd) in txt.
For example: <aaa(::)bbb(:::)ccc>, <(>, <)> -> <aaabbbccc>.",
TxtOutside2Tag);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Text TxtOutHtmTag(Text htmTxt)
//////////////////////////////////////////////////////////////////////////////
{ TxtOutside2Tag(htmTxt, "<", ">") };
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna todos el texto fuera de los tags de html.",
TxtOutHtmTag);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Text TxtOutHtmScr(Text htmTxt)
//////////////////////////////////////////////////////////////////////////////
{ TxtOutHtmTag(TxtOutside2Tag(htmTxt, "<script", "</script>")) };
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna todos el texto fuera de los tags de html y de los scripts.
Sirve para extraer texto limpio del que sacar palabras clave.",
TxtOutHtmScr);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Text TxtReplaceSecuence(Text txtInp, // Texto de entrada
Set repTab) // Tabla de reemplazamientos
//////////////////////////////////////////////////////////////////////////////
{
Real crdTab = Card(repTab); // Numero de cambios a realizar
If(!crdTab, txtInp, // Nada que hacer
{
Text txtNew = Replace(txtInp, repTab[1][1], repTab[1][2]); // Un cambio
TxtReplaceSecuence(txtNew, SetLastN(repTab,crdTab-1)) // Resto de cambios
})
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna un texto resultado de aplicar la tabla de reemplazamientos repTab al
texto de entrada txtIno.
Es una version de ReplaceTable(txtInp, repTab, 1) que garantiza la secuencia
de los reemplazamientos del primero al ultimo de los reemplazamientos.
Es una funcion recursiva.
Cada reemplazamiento solo se efectua una vez.",
TxtReplaceSecuence);
//////////////////////////////////////////////////////////////////////////////
iForense construye las paginas del sitio sobre informática forense Forense.Info
2015 asolver.com | Aviso legal | XHTML | Δ Θ Ξ | Creative Commons | Mapa y funciones del sitio