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

Text TxtInside2Tag()

Text TxtOutside2Tag()

Text TxtOutHtmTag()

Set TxtLineWrap()

Text TxtReplaceSecuence()

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 Omr.Forms

Funciones de texto.

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. Se basa en una version especial de la funcion Txt2Set().
  • Text F(Anything anyVal)
    Retorna numeros, fechas, textos, conjuntos como un texto de formato simple.

Funciones

  • Set Txt2Set(Text txtInp, Text sepTok, Text ctrFun)
    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 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 TxtInside2Tag(Text txtInp, Text tagIni, Text tagEnd)
    Retorna todo el texto entre 2 tags (tagIni y tagEnd) dentro de txtIpn. Por ejemplo: <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, de los scripts e incluye el que esta dentro de los alt y los titles de las imagenes. Sirve para extraer texto limpio del que sacar palabras clave.
  • 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 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.

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) // Set of texts
//////////////////////////////////////////////////////////////////////////////
{ Anything SetGetRand(Txt2Set(txtLst, "|", "CN")) };
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna un texto elegido al azar de entre los tokens (|) de otro texto.
Se basa en una version especial de la funcion Txt2Set().",
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
            Text ctrFun) // C->Compacta, N->Not null, U->Unicos, S->Ordena
//////////////////////////////////////////////////////////////////////////////
{
  Text ctrUpp = ToUpper(ctrFun);

  Set  setSep = Tokenizer(Replace(txtInp, sepTok, Char(7)), Char(7));

  Set  setCmp = If(!TextFind(ctrFun, "C"), setSep,
                   EvalSet(setSep, Text(Text eleTxt) { Compact(eleTxt) }));

  Set  setNot = If(!TextFind(ctrFun, "N"), setCmp,
                   Select(setCmp, Real(Text eleTxt) { eleTxt != "" }));

  Set  setUni = If(!TextFind(ctrFun, "U"), setNot, Unique(setNot));

  Set  setSrt = If(!TextFind(ctrFun, "S"), setUni,
                   Sort(setUni, Real(Text a, Text b) { Compare(a,b) }));

  setSrt
};
//////////////////////////////////////////////////////////////////////////////
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 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 TxtInside2Tag()

//////////////////////////////////////////////////////////////////////////////
Text TxtInside2Tag(Text txtInp, // Texto de entrada
                   Text tagIni, // Tag inicial
                   Text tagEnd) // Tag final
//////////////////////////////////////////////////////////////////////////////
{
  Real posIni = TextFind(txtInp, tagIni);
  Text result = If(LE(posIni,0), "",
  {
    Real lenIni = TextLength(tagIni);
    Real posSub = posIni + lenIni;
    Real posEnd = TextFind(txtInp, tagEnd, posSub);
    If(And(EQ(posIni,1),LE(posEnd,0)), txtInp,
    If(And(GT(posIni,1),LE(posEnd,0)), Sub(txtInp,posIni, TextLength(txtInp)),
       Sub(txtInp,posIni,posEnd+TextLength(tagEnd)-1)+ // Recursion
       TxtInside2Tag(Sub(txtInp, posEnd+TextLength(tagEnd), TextLength(txtInp)),
                     tagIni, tagEnd)))
  });
  ReplaceTable(result, [[ [[tagIni, ""]], [[tagEnd, ""]] ]])
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna todo el texto entre 2 tags (tagIni y tagEnd) dentro de txtIpn.
Por ejemplo: <aaa(::)bbb(---)ccc>, <(>, <)> -> <::--->.",
TxtInside2Tag);
//////////////////////////////////////////////////////////////////////////////

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)
//////////////////////////////////////////////////////////////////////////////
{
  Text notScr = TxtOutside2Tag(htmTxt, "<script", "</script>"); // No scripts
  Text notAmp = TxtOutside2Tag(notScr, "&",       ";");         // No &xxx;
  Text notHtm = TxtOutside2Tag(notAmp, "<",       ">");         // No html
  
  Text htmQuo = Replace(htmTxt, Char(34), "'"); // Unifica comillas
  Text difSep = Char(7);    // Separador no usual
  Text difEnd = difSep+" "; // Terminador no usual
  
  Text titTag = "title='";  // Titulos de la imagenes separados por un blanco
  Text titTxt = TxtInside2Tag(Replace(htmQuo, titTag, difEnd), difSep, "'");

  Text altTag = "alt='";    // Alts de la imagenes separados por un blanco
  Text altTxt = TxtInside2Tag(Replace(htmQuo, altTag, difEnd), difSep, "'");

  Compact(notHtm + titTxt + altTxt)
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna todos el texto fuera de los tags de html, de los scripts e incluye
el que esta dentro de los alt y los titles de las imagenes.
Sirve para extraer texto limpio del que sacar palabras clave.",
TxtOutHtmTag);
//////////////////////////////////////////////////////////////////////////////

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

Time oriented language

//////////////////////////////////////////////////////////////////////////////
// FILE    : txt.tol
// AUTHOR  : http://www.asolver.com
// PURPOSE : Funciones de texto.
//////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////
// 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) // Set of texts
//////////////////////////////////////////////////////////////////////////////
{ Anything SetGetRand(Txt2Set(txtLst, "|", "CN")) };
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna un texto elegido al azar de entre los tokens (|) de otro texto.
Se basa en una version especial de la funcion Txt2Set().",
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
            Text ctrFun) // C->Compacta, N->Not null, U->Unicos, S->Ordena
//////////////////////////////////////////////////////////////////////////////
{
  Text ctrUpp = ToUpper(ctrFun);

  Set  setSep = Tokenizer(Replace(txtInp, sepTok, Char(7)), Char(7));

  Set  setCmp = If(!TextFind(ctrFun, "C"), setSep,
                   EvalSet(setSep, Text(Text eleTxt) { Compact(eleTxt) }));

  Set  setNot = If(!TextFind(ctrFun, "N"), setCmp,
                   Select(setCmp, Real(Text eleTxt) { eleTxt != "" }));

  Set  setUni = If(!TextFind(ctrFun, "U"), setNot, Unique(setNot));

  Set  setSrt = If(!TextFind(ctrFun, "S"), setUni,
                   Sort(setUni, Real(Text a, Text b) { Compare(a,b) }));

  setSrt
};
//////////////////////////////////////////////////////////////////////////////
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 TxtInside2Tag(Text txtInp, // Texto de entrada
                   Text tagIni, // Tag inicial
                   Text tagEnd) // Tag final
//////////////////////////////////////////////////////////////////////////////
{
  Real posIni = TextFind(txtInp, tagIni);
  Text result = If(LE(posIni,0), "",
  {
    Real lenIni = TextLength(tagIni);
    Real posSub = posIni + lenIni;
    Real posEnd = TextFind(txtInp, tagEnd, posSub);
    If(And(EQ(posIni,1),LE(posEnd,0)), txtInp,
    If(And(GT(posIni,1),LE(posEnd,0)), Sub(txtInp,posIni, TextLength(txtInp)),
       Sub(txtInp,posIni,posEnd+TextLength(tagEnd)-1)+ // Recursion
       TxtInside2Tag(Sub(txtInp, posEnd+TextLength(tagEnd), TextLength(txtInp)),
                     tagIni, tagEnd)))
  });
  ReplaceTable(result, [[ [[tagIni, ""]], [[tagEnd, ""]] ]])
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna todo el texto entre 2 tags (tagIni y tagEnd) dentro de txtIpn.
Por ejemplo: <aaa(::)bbb(---)ccc>, <(>, <)> -> <::--->.",
TxtInside2Tag);
//////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////
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)
//////////////////////////////////////////////////////////////////////////////
{
  Text notScr = TxtOutside2Tag(htmTxt, "<script", "</script>"); // No scripts
  Text notAmp = TxtOutside2Tag(notScr, "&",       ";");         // No &xxx;
  Text notHtm = TxtOutside2Tag(notAmp, "<",       ">");         // No html
  
  Text htmQuo = Replace(htmTxt, Char(34), "'"); // Unifica comillas
  Text difSep = Char(7);    // Separador no usual
  Text difEnd = difSep+" "; // Terminador no usual
  
  Text titTag = "title='";  // Titulos de la imagenes separados por un blanco
  Text titTxt = TxtInside2Tag(Replace(htmQuo, titTag, difEnd), difSep, "'");

  Text altTag = "alt='";    // Alts de la imagenes separados por un blanco
  Text altTxt = TxtInside2Tag(Replace(htmQuo, altTag, difEnd), difSep, "'");

  Compact(notHtm + titTxt + altTxt)
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna todos el texto fuera de los tags de html, de los scripts e incluye
el que esta dentro de los alt y los titles de las imagenes.
Sirve para extraer texto limpio del que sacar palabras clave.",
TxtOutHtmTag);
//////////////////////////////////////////////////////////////////////////////


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

Árbol de ficheros

Omr.Forms construye las páginas web Html del sitio web omrforms.es

  • make.tol proceso principal de generación del sitio web omrforms.es
  • tol directorios de código Tol
    • cmm funciones comunes
    • app funciones específicas de la aplicación
      • pdb.tol de manejo de los posts de una agenda
      • key.tol generación de palabras clave para páginas
    • inc.tol para la inclusión de ficheros Tol
  • agenda directorio destinado a la única agenda de post
    • agendadb.age ejemplo de un conjunto de posts de contenido para publicar
  • web directorio destinado a las páginas web generadas
    • css directorio para ficheros de estilo Cascade Style Sheet
      • common.css fichero de estilo para las páginas Html
    • seed.htm semilla de página Html con Tol embebido para generar otras
    • sitemap.xml mapa del sitio web generado automáticamente en Xml
    • preciospresupuestoslecturaoptica.html ejemplo del código Html de una de las páginas web generadas
  • ejemplos.html ejemplos visuales de 3 páginas Html generadas automáticamente
  • omr_forms.pdf documento resumen de funciones del programa constructor de web

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

Tol