Secciones de la página

txt. tol


Declaraciones


Funciones de nombre corto


Funciones


Time oriented language


Árbol de ficheros

Funciones

Text Q()

Text W()

Text R()

Text F()

Set Txt2Set()

Set TxtTokenizer()

Text TxtReplaceFirst()

Text TxtBetween2Tag()

Text TxtInside2TagPlus()

Text TxtOutside2Tag()

Text TxtOutHtmTag()

Text TxtOutHtmScr()

Text TxtReplaceSecuence()

Set TxtForChr()

Set TxtLineWrap()

Text TxtTwitterWrap()

Tol

Artículos del sitio

Presentación de Tol

Todos los programas

Simuladores visuales

Sitios que me gustan

Por categorías

Algoritmia

Búsqueda y ordenación

Computación fisiológica

Editorial y edición

Gráficos de datos

Herramientas y utilidades

Hipertexto

Informática forense

Lectura óptica de datos

Metaprogramación

No determinista

Ofimática

Recursión e iteración

Reglas y restricciones

Series y estadística









txt.tol de con-Q.tv

Text functions.

Declaraciones

Funciones de nombre corto

  • Text Q(Text txtVal)
    Retorna un texto entre dobles comillas. Equivalente a la funcion Tol Qt().
  • Text W(Text txtVal)
    Retorna un camino en formato Unix convertido a formato Windows/DOS.
  • Text R(Text txtLst)
    Retorna un texto elegido al azar de entre los tokens (|) de otro texto.
  • Text F(Anything anyVal)
    Retorna numeros, fechas, textos, conjuntos como un texto de formato simple.

Funciones

  • Set Txt2Set(Text txtInp, Text sepTok)
    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.
  • Set TxtTokenizer(Text txtInp, Text tagBrk)
    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.
  • Text TxtReplaceFirst(Text txtInp, Text txtOld, Text txtNew)
    Returns the result of change, only the very first time, in the input text txtInp the old text txtOld by the new text txtNew.
  • Text TxtBetween2Tag(Text inpTxt, Text tagIni, Text tagEnd, Real cmpFlg)
    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'.
  • Text TxtInside2TagPlus(Text txtInp, Text tagIni, Text tagEnd)
    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>, <(>, <)> -> <(::)(---)>.
  • Text TxtOutside2Tag(Text txtInp, Text tagIni, Text tagEnd)
    Returns all the texts outside 2 tags (tagIni and tagEnd) in txt. For example: <aaa(::)bbb(:::)ccc>, <(>, <)> -> <aaabbbccc>.
  • Text TxtOutHtmTag(Text htmTxt)
    Retorna todos el texto fuera de los tags de html.
  • Text TxtOutHtmScr(Text htmTxt)
    Retorna todos el texto fuera de los tags de html y de los scripts. Sirve para extraer texto limpio del que sacar palabras clave.
  • Text TxtReplaceSecuence(Text txtInp, Set repTab)
    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.
  • Set TxtForChr(Text inpTxt, Code funChr)
    Retorna el conjunto resultado de aplicar la funcion funChr(Text oneChr) a todos los caracteres del texto de entrada txtInp. Retorna un Set a imagen de las funciones basicas For() y EvalSet().
  • Set TxtLineWrap(Text txtInp, Real linMax, Real cmpCtr)
    Retorna un conjunto de 2 texto el primero con un máximo de linMax caracteres y el segundo con el resto. Es el resultado de cortar txtInp por el primer blanco que permita que el corte cumpla la condición inicial. Si el texto de entrada es mas corte que linMax retorna un conjunto formado por el texto inicial y la tira vacia. Si el corte es imposible busca el mejor corte posible y si no lo encuentra retorna un conjunto formado por el texto inicial y la tira vacia. Si cmpCtr es true los resultados son compactados. Tambien existe en Tol la funcion Wrap() con ciertas semejanzas, aunque mas a TxtParagraphWrap().
  • Text TxtTwitterWrap(Text txtCut, Text txtNot)
    Retorna un texto que no supere el maximo de caracteres de Twitter a partir de un texto inicial que se puede cortar y uno final que no se puede.

Funciones de nombre corto

Text Q()

//////////////////////////////////////////////////////////////////////////////
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 W(Text txtVal) // Text
//////////////////////////////////////////////////////////////////////////////
{ Replace(txtVal, "/", "\\") };
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna un camino en formato Unix convertido a formato Windows/DOS.",
W);
//////////////////////////////////////////////////////////////////////////////

Text R()

//////////////////////////////////////////////////////////////////////////////
Text R(Text txtLst) // List of texts separated with |
//////////////////////////////////////////////////////////////////////////////
{ SetGetRand(Txt2Set(txtLst, "|")) };
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna un texto elegido al azar de entre los tokens (|) de otro texto.",
R);
//////////////////////////////////////////////////////////////////////////////

Text F()

//////////////////////////////////////////////////////////////////////////////
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);
//////////////////////////////////////////////////////////////////////////////

Funciones

Set Txt2Set()

//////////////////////////////////////////////////////////////////////////////
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()

//////////////////////////////////////////////////////////////////////////////
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 TxtReplaceFirst()

//////////////////////////////////////////////////////////////////////////////
Text TxtReplaceFirst(Text txtInp, // Input text
                     Text txtOld, // Old text
                     Text txtNew) // New text
//////////////////////////////////////////////////////////////////////////////
{
  Real posIni = TextFind(txtInp, txtOld);
  Text result = If(LE(posIni,0), txtInp, // No aparece, no se cambia nada
  {
    Real lenIni = TextLength(txtOld);
    Real posSub = posIni + lenIni;
    Real posEnd = TextLength(txtInp);
    Sub(txtInp, 1, posIni-1) + txtNew + Sub(txtInp, posSub, posEnd)
  })
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns the result of change, only the very first time, in the input text
txtInp the old text txtOld by the new text txtNew.",
TxtReplaceFirst);
//////////////////////////////////////////////////////////////////////////////

Text TxtBetween2Tag()

//////////////////////////////////////////////////////////////////////////////
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 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 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 TxtOutHtmTag(Text htmTxt)
//////////////////////////////////////////////////////////////////////////////
{ TxtOutside2Tag(htmTxt, "<", ">") };
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna todos el texto fuera de los tags de html.",
TxtOutHtmTag);
//////////////////////////////////////////////////////////////////////////////

Text TxtOutHtmScr()

//////////////////////////////////////////////////////////////////////////////
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 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);
//////////////////////////////////////////////////////////////////////////////

Set TxtForChr()

//////////////////////////////////////////////////////////////////////////////
Set TxtForChr(Text inpTxt, // Texto de entrada
              Code funChr) // Funcion tipo Anything(Text oneChr)
//////////////////////////////////////////////////////////////////////////////
{
  Real lenTxt = TextLength(inpTxt);
  For(1, lenTxt, Anything(Real posTxt) { funChr(Sub(inpTxt,posTxt,posTxt)) })
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna el conjunto resultado de aplicar la funcion funChr(Text oneChr)
a todos los caracteres del texto de entrada txtInp.
Retorna un Set a imagen de las funciones basicas For() y EvalSet().",
TxtForChr);
//////////////////////////////////////////////////////////////////////////////

Set TxtLineWrap()

//////////////////////////////////////////////////////////////////////////////
Set  TxtLineWrap(Text txtInp, // Texto de entrada
                 Real linMax, // Maximo numero de caracteres por linea
                 Real cmpCtr) // Si true entonces compacta
//////////////////////////////////////////////////////////////////////////////
{
  Text txtCmp = If(cmpCtr, Compact(txtInp), txtInp);
  Text txtRev = Reverse(txtCmp);
  Real txtLen = TextLength(txtCmp);
  Set  cutSet = If(LE(txtLen, linMax), [[txtCmp, ""]], // Ya esta hecho
  {
    Real blkPos = TextFind(txtRev, " ", txtLen-linMax); // Busca para atras

    If(GE(blkPos, 1),
    {
      SetOfText(Sub(txtCmp, 0,               txtLen-blkPos),
                Sub(txtCmp, txtLen-blkPos+1, txtLen))
    },
    {
      // No se puede cortar
      Real blkBad = TextFind(txtCmp, " ", linMax+1); // Busca hacia adelante

      If(LT(blkBad, 0), [[txtCmp, ""]], // No hay corte posible
      {
        SetOfText(Sub(txtCmp, 0,        blkBad-1), // Hay un mal corte
                  Sub(txtCmp, blkBad+1, txtLen))
      })
    })
  });
  If(cmpCtr, SetOfText(Compact(cutSet[1]),Compact(cutSet[2])), cutSet)
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna un conjunto de 2 texto el primero con un máximo de linMax caracteres
y el segundo con el resto.
Es el resultado de cortar txtInp por el primer blanco que permita que el corte
cumpla la condición inicial.
Si el texto de entrada es mas corte que linMax retorna un conjunto formado
por el texto inicial y la tira vacia.
Si el corte es imposible busca el mejor corte posible y si no lo encuentra
retorna un conjunto formado por el texto inicial y la tira vacia.
Si cmpCtr es true los resultados son compactados.
Tambien existe en Tol la funcion Wrap() con ciertas semejanzas,
aunque mas a TxtParagraphWrap().",
TxtLineWrap);
//////////////////////////////////////////////////////////////////////////////

Text TxtTwitterWrap()

//////////////////////////////////////////////////////////////////////////////
Text TxtTwitterWrap(Text txtCut, // Texto inicial cortable
                    Text txtNot) // Texto final no cortable
//////////////////////////////////////////////////////////////////////////////
{
  Real chrTwi = 117;  // Number of characters for Twitter, teoricamente 140

  Set  setTwi = TxtLineWrap(txtCut, chrTwi-TextLength(txtNot), TRUE);
  
  Compact(setTwi[1]+txtNot)
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna un texto que no supere el maximo de caracteres de Twitter a partir
de un texto inicial que se puede cortar y uno final que no se puede.",
TxtTwitterWrap);
//////////////////////////////////////////////////////////////////////////////

Time oriented language

//////////////////////////////////////////////////////////////////////////////
// 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 R(Text txtLst) // List of texts separated with |
//////////////////////////////////////////////////////////////////////////////
{ SetGetRand(Txt2Set(txtLst, "|")) };
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna un texto elegido al azar de entre los tokens (|) de otro texto.",
R);
//////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////
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 TxtReplaceFirst(Text txtInp, // Input text
                     Text txtOld, // Old text
                     Text txtNew) // New text
//////////////////////////////////////////////////////////////////////////////
{
  Real posIni = TextFind(txtInp, txtOld);
  Text result = If(LE(posIni,0), txtInp, // No aparece, no se cambia nada
  {
    Real lenIni = TextLength(txtOld);
    Real posSub = posIni + lenIni;
    Real posEnd = TextLength(txtInp);
    Sub(txtInp, 1, posIni-1) + txtNew + Sub(txtInp, posSub, posEnd)
  })
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns the result of change, only the very first time, in the input text
txtInp the old text txtOld by the new text txtNew.",
TxtReplaceFirst);
//////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////
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);
//////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////
Set TxtForChr(Text inpTxt, // Texto de entrada
              Code funChr) // Funcion tipo Anything(Text oneChr)
//////////////////////////////////////////////////////////////////////////////
{
  Real lenTxt = TextLength(inpTxt);
  For(1, lenTxt, Anything(Real posTxt) { funChr(Sub(inpTxt,posTxt,posTxt)) })
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna el conjunto resultado de aplicar la funcion funChr(Text oneChr)
a todos los caracteres del texto de entrada txtInp.
Retorna un Set a imagen de las funciones basicas For() y EvalSet().",
TxtForChr);
//////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////
Set  TxtLineWrap(Text txtInp, // Texto de entrada
                 Real linMax, // Maximo numero de caracteres por linea
                 Real cmpCtr) // Si true entonces compacta
//////////////////////////////////////////////////////////////////////////////
{
  Text txtCmp = If(cmpCtr, Compact(txtInp), txtInp);
  Text txtRev = Reverse(txtCmp);
  Real txtLen = TextLength(txtCmp);
  Set  cutSet = If(LE(txtLen, linMax), [[txtCmp, ""]], // Ya esta hecho
  {
    Real blkPos = TextFind(txtRev, " ", txtLen-linMax); // Busca para atras

    If(GE(blkPos, 1),
    {
      SetOfText(Sub(txtCmp, 0,               txtLen-blkPos),
                Sub(txtCmp, txtLen-blkPos+1, txtLen))
    },
    {
      // No se puede cortar
      Real blkBad = TextFind(txtCmp, " ", linMax+1); // Busca hacia adelante

      If(LT(blkBad, 0), [[txtCmp, ""]], // No hay corte posible
      {
        SetOfText(Sub(txtCmp, 0,        blkBad-1), // Hay un mal corte
                  Sub(txtCmp, blkBad+1, txtLen))
      })
    })
  });
  If(cmpCtr, SetOfText(Compact(cutSet[1]),Compact(cutSet[2])), cutSet)
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna un conjunto de 2 texto el primero con un máximo de linMax caracteres
y el segundo con el resto.
Es el resultado de cortar txtInp por el primer blanco que permita que el corte
cumpla la condición inicial.
Si el texto de entrada es mas corte que linMax retorna un conjunto formado
por el texto inicial y la tira vacia.
Si el corte es imposible busca el mejor corte posible y si no lo encuentra
retorna un conjunto formado por el texto inicial y la tira vacia.
Si cmpCtr es true los resultados son compactados.
Tambien existe en Tol la funcion Wrap() con ciertas semejanzas,
aunque mas a TxtParagraphWrap().",
TxtLineWrap);
//////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////
Text TxtTwitterWrap(Text txtCut, // Texto inicial cortable
                    Text txtNot) // Texto final no cortable
//////////////////////////////////////////////////////////////////////////////
{
  Real chrTwi = 117;  // Number of characters for Twitter, teoricamente 140

  Set  setTwi = TxtLineWrap(txtCut, chrTwi-TextLength(txtNot), TRUE);
  
  Compact(setTwi[1]+txtNot)
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna un texto que no supere el maximo de caracteres de Twitter a partir
de un texto inicial que se puede cortar y uno final que no se puede.",
TxtTwitterWrap);
//////////////////////////////////////////////////////////////////////////////

Árbol de ficheros

con-Q.tv construye las páginas del sitio y newsletter Con-Q.tv

  • make.tol proceso principal de generacion del sitio web y la newsletter
  • tol directorios de código Tol
    • cmm funciones comunes
      • txt.tol funciones de textos
      • set.tol funciones de conjuntos
      • fil.tol funciones de ficheros
      • dir.tol funciones directorios
      • tme.tol funciones del macro-expansor de Tol en Html
      • img.tol funciones de imagenes Html
      • ftp.tol para generar mandatos para hacer Ftp
      • xsm.tol para construir sitemaps en Xml
    • app funciones especificas de aplicacion
      • ads.tol funciones de anuncios de publicidad
      • pdb.tol funciones de manejo de los posts de una agenda
      • pht.tol funciones auxiliares para el Html de los post
    • inc.tol para la inclusión de ficheros Tol
  • agenda directorio destinado a la agenda de post
  • web directorio destinado a las páginas web generadas
    • css directorio para ficheros de estilo
      • common.css fichero de estilo Css para las páginas Html
    • seed directorio para ficheros semilla
      • seed.htm semilla de página Html con Tol embebido
      • lopd.htm texto Lopd para insertar en la newsletter de envío por email
    • src directorio para ficheros con código Javascript
      • common.js funciones Javascript para diferentes redes sociales
    • noticia directorio para páginas de noticias
    • quiosco directorio para páginas Html de categorias
      • asamblea.html ejemplo de página de categoría generada automáticamente
    • sitemap.xml mapa completo del sitio web generado en Xml automáticamente
  • presentacion.html vídeo de presentación de la Newsletter de la Avppm
  • con-q_tv.pdf documento resumen de funciones del programa de la newsletter

2015 asolver.com | Aviso legal | XHTML | Δ Θ Ξ | Creative Commons | Mapa y funciones del sitio

Tol