Secciones de la página

txt. tol


Declaraciones


Funciones


Time oriented language


Árbol de ficheros

Funciones

Date Txt2Dte()

Real Txt2Month()

Set Txt2Set()

Text TxtBetween2Tag()

Text TxtInside2Tag()

Text TxtOutside2Tag()

Text TxtOutHtmTag()

Text TxtOutHtmScr()

Text TxtRand()

Set TxtTokenizer()

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 Ink.Watercolor

Text functions.

Declaraciones

Funciones

  • Date Txt2Dte(Text txt, Text fmt)
    Returns a date from a text using some formats. dd/mmm/yyyy | 07/Aug/2003 -> y2003m08d07 If the format is unknown returns the UnknownDate.
  • Real Txt2Month(Text txt)
    Returns a month number from the english, spanish, portuguese or french month names (using this order). If several months names match then returns the first one. If none month match then returns 0.
  • Set Txt2Set(Text txt, Set sep, Real cmp)
    Returns a set of texts like TOL function Tokenizer(). Can use a set of separators of any length. Assumes that there are not Char(1) inside the text. If argument sep is the Empty set then assumes ; as default separator. If argument cmp is true then apply the Compact() function. For example: Txt2Set(' a / b -- c / d / e / f ', [['/','--']], TRUE) returns [['a','b','c','d','e','f']]
  • Text TxtBetween2Tag(Text txt, Text tagIni, Text tagEnd, Real cmp)
    Returns a subtext of text between the first ocurrence of tagIni and tagEnd. If tagIni or tagEnd does not ocurr then returns the empty text. If cmp argument is true then apply the Compact() function to the returning text. For example: TxtBetween2Tag('a b [[ c ]] d [[ e ]] f', '[[', ']]', TRUE) returns a 'c'. There are other version of this function with more functionalities.
  • Text TxtInside2Tag(Text txt, Text tagIni, Text tagEnd)
    Returns all the texts between 2 tags (tagIni and tagEnd) in txt. 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)
    Returns all text outside the Html tags.
  • Text TxtOutHtmScr(Text htmTxt)
    Returns all text outside the Html tags and outside the scripts.
  • Text TxtRand(Real len)
    Returns a random text with len chars from A to Z. Use Min() y Max() because in some old versions of TOL the Rand() functions sometimes returns numbers out of range.
  • Set TxtTokenizer(Text txtInp, Text tagBrk)
    Returns a set breaking the input text txtInp by the token tagBrk. The lenght of the token tagBrk can be 1 or more characters. This function use the Tol function Tokenizer() that breaks by only one character. This function assume that txtInp do not contain the character 7 (bell).

Funciones

Date Txt2Dte()

//////////////////////////////////////////////////////////////////////////////
Date Txt2Dte(Text txt, // Text
             Text fmt) // Format
//////////////////////////////////////////////////////////////////////////////
{
  Case
  (
    fmt=="dd/mmm/yyyy",
    { //  123456789.1
      Real day = Eval     (Sub(txt, 1, 2)+"; ");
      Real yea = Eval     (Sub(txt, 8,11)+"; ");
      Real mth = Txt2Month(Sub(txt, 4, 6));
      If(Not(mth), UnknownDate, YMD(yea, mth, day))
    },
    TRUE, UnknownDate
  )
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns a date from a text using some formats.
dd/mmm/yyyy | 07/Aug/2003 -> y2003m08d07
If the format is unknown returns the UnknownDate.",
Txt2Dte);
//////////////////////////////////////////////////////////////////////////////

Real Txt2Month()

//////////////////////////////////////////////////////////////////////////////
Real Txt2Month(Text txt) // Text 3 or more letter
//////////////////////////////////////////////////////////////////////////////
{
  Set engSet = SetTxtBeginWith(SetEnglishMonth, txt, FALSE);
  If(GT(Card(engSet), 0), engSet[1],
  {
    Set spaSet = SetTxtBeginWith(SetSpanishMonth, txt, FALSE);
    If(GT(Card(spaSet), 0), spaSet[1], 
    {
      Set porSet = SetTxtBeginWith(SetPortugueseMonth, txt, FALSE);
      If(GT(Card(porSet), 0), porSet[1], 
      {
        Set freSet = SetTxtBeginWith(SetFrenchMonth, txt, FALSE);
        If(GT(Card(freSet), 0), freSet[1], 0)
      })
    })
  })
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns a month number from the english, spanish, portuguese or french month
names (using this order).
If several months names match then returns the first one.
If none month match then returns 0.",
Txt2Month);
//////////////////////////////////////////////////////////////////////////////

Set Txt2Set()

//////////////////////////////////////////////////////////////////////////////
Set Txt2Set(Text txt, // Text
            Set  sep, // Set of separators
            Real cmp) // If true apply the Compact() function
//////////////////////////////////////////////////////////////////////////////
{
  Text sepUni = Char(1); // Unique separator with only one character
  Set  sepTab = If(EQ(Card(sep),0), [[ [[";", sepUni ]] ]],
                   EvalSet(sep, Set(Text s) { [[s, sepUni]] }));
  Text txtRep = ReplaceTable(txt, sepTab);
  Set  setTok = Tokenizer(txtRep, sepUni);
  If(cmp, EvalSet(setTok, Text(Text txt) { Compact(txt) }), setTok)
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns a set of texts like TOL function Tokenizer().
Can use a set of separators of any length.
Assumes that there are not Char(1) inside the text.
If argument sep is the Empty set then assumes ; as default separator.
If argument cmp is true then apply the Compact() function.
For example: Txt2Set(' a / b -- c / d / e / f ', [['/','--']], TRUE)
returns [['a','b','c','d','e','f']]",
Txt2Set);
//////////////////////////////////////////////////////////////////////////////

Text TxtBetween2Tag()

//////////////////////////////////////////////////////////////////////////////
Text TxtBetween2Tag(Text txt,    // Text
                    Text tagIni, // Initial tag
                    Text tagEnd, // End tag
                    Real cmp)    // If true apply the Compact() function
//////////////////////////////////////////////////////////////////////////////
{
  Real posIni = TextFind(txt, tagIni);
  Text result =
    If(LE(posIni,0), "",
          {
            Real lenIni = TextLength(tagIni);
            Real posSub = posIni + lenIni;
            Real posEnd = TextFind(txt, tagEnd, posSub);
            Text subTxt = If(LE(posEnd,0), 
                             Sub(txt,posSub,TextLength(txt)),
                             Sub(txt,posSub,posEnd-1));
            subTxt
          });
  If(cmp, Compact(result), result)
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns a subtext of text between the first ocurrence of tagIni and tagEnd.
If tagIni or tagEnd does not ocurr then returns the empty text.
If cmp argument is true then apply the Compact() function to the returning
text.
For example: TxtBetween2Tag('a b [[ c ]] d [[ e ]] f', '[[', ']]', TRUE)
returns a 'c'.
There are other version of this function with more functionalities.",
TxtBetween2Tag);
//////////////////////////////////////////////////////////////////////////////

Text TxtInside2Tag()

//////////////////////////////////////////////////////////////////////////////
Text TxtInside2Tag(Text txt, Text tagIni, Text tagEnd)
// 
//////////////////////////////////////////////////////////////////////////////
{
  Real posIni = TextFind(txt, tagIni);
  Text result = If(LE(posIni,0), "",
  {
    Real lenIni = TextLength(tagIni);
    Real posSub = posIni + lenIni;
    Real posEnd = TextFind(txt, tagEnd, posSub);
    If(And(EQ(posIni,1),LE(posEnd,0)), txt,
    If(And(GT(posIni,1),LE(posEnd,0)), Sub(txt,posIni, TextLength(txt)),
       Sub(txt,posIni,posEnd+TextLength(tagEnd)-1)+ // Recursion
       TxtInside2Tag(Sub(txt, posEnd+TextLength(tagEnd), TextLength(txt)),
                     tagIni, tagEnd)))
  });
  ReplaceTable(result, [[ [[tagIni, ""]], [[tagEnd, ""]] ]])
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns all the texts between 2 tags (tagIni and tagEnd) in txt.
For example: <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)
//////////////////////////////////////////////////////////////////////////////
{ TxtOutside2Tag(htmTxt, "<", ">") };
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns all text outside the Html tags.",
TxtOutHtmTag);
//////////////////////////////////////////////////////////////////////////////

Text TxtOutHtmScr()

//////////////////////////////////////////////////////////////////////////////
Text TxtOutHtmScr(Text htmTxt)
//////////////////////////////////////////////////////////////////////////////
{ TxtOutHtmTag(TxtOutside2Tag(htmTxt, "<script", "</script>")) };
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns all text outside the Html tags and outside the scripts.",
TxtOutHtmScr);
//////////////////////////////////////////////////////////////////////////////

Text TxtRand()

//////////////////////////////////////////////////////////////////////////////
Text TxtRand(Real len) // Random text length
//////////////////////////////////////////////////////////////////////////////
{ SetSum(For(1,len,Text(Real t) { Char(Min(90,Max(65,Rand(64,91)))) })) };
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns a random text with len chars from A to Z.
Use Min() y Max() because in some old versions of TOL the Rand() functions
sometimes returns numbers out of range.",
TxtRand);
//////////////////////////////////////////////////////////////////////////////

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(
"Returns a set breaking the input text txtInp by the token tagBrk.
The lenght of the token tagBrk can be 1 or more characters. This function use
the Tol function Tokenizer() that breaks by only one character.
This function assume that txtInp do not contain the character 7 (bell).",
TxtTokenizer);
//////////////////////////////////////////////////////////////////////////////

Time oriented language

//////////////////////////////////////////////////////////////////////////////
// FILE    : txt.tol
// AUTHOR  : http://www.asolver.com
// PURPOSE : Text functions.
//////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////
// FUNCTIONS
//////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////
Date Txt2Dte(Text txt, // Text
             Text fmt) // Format
//////////////////////////////////////////////////////////////////////////////
{
  Case
  (
    fmt=="dd/mmm/yyyy",
    { //  123456789.1
      Real day = Eval     (Sub(txt, 1, 2)+"; ");
      Real yea = Eval     (Sub(txt, 8,11)+"; ");
      Real mth = Txt2Month(Sub(txt, 4, 6));
      If(Not(mth), UnknownDate, YMD(yea, mth, day))
    },
    TRUE, UnknownDate
  )
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns a date from a text using some formats.
dd/mmm/yyyy | 07/Aug/2003 -> y2003m08d07
If the format is unknown returns the UnknownDate.",
Txt2Dte);
//////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////
Real Txt2Month(Text txt) // Text 3 or more letter
//////////////////////////////////////////////////////////////////////////////
{
  Set engSet = SetTxtBeginWith(SetEnglishMonth, txt, FALSE);
  If(GT(Card(engSet), 0), engSet[1],
  {
    Set spaSet = SetTxtBeginWith(SetSpanishMonth, txt, FALSE);
    If(GT(Card(spaSet), 0), spaSet[1], 
    {
      Set porSet = SetTxtBeginWith(SetPortugueseMonth, txt, FALSE);
      If(GT(Card(porSet), 0), porSet[1], 
      {
        Set freSet = SetTxtBeginWith(SetFrenchMonth, txt, FALSE);
        If(GT(Card(freSet), 0), freSet[1], 0)
      })
    })
  })
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns a month number from the english, spanish, portuguese or french month
names (using this order).
If several months names match then returns the first one.
If none month match then returns 0.",
Txt2Month);
//////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////
Set Txt2Set(Text txt, // Text
            Set  sep, // Set of separators
            Real cmp) // If true apply the Compact() function
//////////////////////////////////////////////////////////////////////////////
{
  Text sepUni = Char(1); // Unique separator with only one character
  Set  sepTab = If(EQ(Card(sep),0), [[ [[";", sepUni ]] ]],
                   EvalSet(sep, Set(Text s) { [[s, sepUni]] }));
  Text txtRep = ReplaceTable(txt, sepTab);
  Set  setTok = Tokenizer(txtRep, sepUni);
  If(cmp, EvalSet(setTok, Text(Text txt) { Compact(txt) }), setTok)
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns a set of texts like TOL function Tokenizer().
Can use a set of separators of any length.
Assumes that there are not Char(1) inside the text.
If argument sep is the Empty set then assumes ; as default separator.
If argument cmp is true then apply the Compact() function.
For example: Txt2Set(' a / b -- c / d / e / f ', [['/','--']], TRUE)
returns [['a','b','c','d','e','f']]",
Txt2Set);
//////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////
Text TxtBetween2Tag(Text txt,    // Text
                    Text tagIni, // Initial tag
                    Text tagEnd, // End tag
                    Real cmp)    // If true apply the Compact() function
//////////////////////////////////////////////////////////////////////////////
{
  Real posIni = TextFind(txt, tagIni);
  Text result =
    If(LE(posIni,0), "",
          {
            Real lenIni = TextLength(tagIni);
            Real posSub = posIni + lenIni;
            Real posEnd = TextFind(txt, tagEnd, posSub);
            Text subTxt = If(LE(posEnd,0), 
                             Sub(txt,posSub,TextLength(txt)),
                             Sub(txt,posSub,posEnd-1));
            subTxt
          });
  If(cmp, Compact(result), result)
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns a subtext of text between the first ocurrence of tagIni and tagEnd.
If tagIni or tagEnd does not ocurr then returns the empty text.
If cmp argument is true then apply the Compact() function to the returning
text.
For example: TxtBetween2Tag('a b [[ c ]] d [[ e ]] f', '[[', ']]', TRUE)
returns a 'c'.
There are other version of this function with more functionalities.",
TxtBetween2Tag);
//////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////
Text TxtInside2Tag(Text txt, Text tagIni, Text tagEnd)
// 
//////////////////////////////////////////////////////////////////////////////
{
  Real posIni = TextFind(txt, tagIni);
  Text result = If(LE(posIni,0), "",
  {
    Real lenIni = TextLength(tagIni);
    Real posSub = posIni + lenIni;
    Real posEnd = TextFind(txt, tagEnd, posSub);
    If(And(EQ(posIni,1),LE(posEnd,0)), txt,
    If(And(GT(posIni,1),LE(posEnd,0)), Sub(txt,posIni, TextLength(txt)),
       Sub(txt,posIni,posEnd+TextLength(tagEnd)-1)+ // Recursion
       TxtInside2Tag(Sub(txt, posEnd+TextLength(tagEnd), TextLength(txt)),
                     tagIni, tagEnd)))
  });
  ReplaceTable(result, [[ [[tagIni, ""]], [[tagEnd, ""]] ]])
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns all the texts between 2 tags (tagIni and tagEnd) in txt.
For example: <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)
//////////////////////////////////////////////////////////////////////////////
{ TxtOutside2Tag(htmTxt, "<", ">") };
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns all text outside the Html tags.",
TxtOutHtmTag);
//////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////
Text TxtOutHtmScr(Text htmTxt)
//////////////////////////////////////////////////////////////////////////////
{ TxtOutHtmTag(TxtOutside2Tag(htmTxt, "<script", "</script>")) };
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns all text outside the Html tags and outside the scripts.",
TxtOutHtmScr);
//////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////
Text TxtRand(Real len) // Random text length
//////////////////////////////////////////////////////////////////////////////
{ SetSum(For(1,len,Text(Real t) { Char(Min(90,Max(65,Rand(64,91)))) })) };
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns a random text with len chars from A to Z.
Use Min() y Max() because in some old versions of TOL the Rand() functions
sometimes returns numbers out of range.",
TxtRand);
//////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////
Set TxtTokenizer(Text txtInp, // Texto de entrada
                 Text tagBrk) // Tag por el que se corta
//////////////////////////////////////////////////////////////////////////////
{ Tokenizer(Replace(txtInp, tagBrk, Char(7)), Char(7)) };
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns a set breaking the input text txtInp by the token tagBrk.
The lenght of the token tagBrk can be 1 or more characters. This function use
the Tol function Tokenizer() that breaks by only one character.
This function assume that txtInp do not contain the character 7 (bell).",
TxtTokenizer);
//////////////////////////////////////////////////////////////////////////////

Árbol de ficheros

Ink.Watercolor construye las páginas del sitio web inkwatercolor.com

  • make.tol proceso principal de generación de contenidos del sitio web
  • tol directorios de código fuente en lenguaje de programación Tol
    • cmm funciones comunes de textos, fechas, conjuntos, ficheros, etc.
      • txt.tol funciones de manejo de textos
      • set.tol funciones de manejo de conjuntos
      • tab.tol funciones de tablas como set of sets
      • ser.tol funciones de series temporales
      • fil.tol funciones de gestión de ficheros
      • zip.tol compresor de ficheros en línea de mandatos
      • apa.tol proceso de ficheros de log de Apache
      • dir.tol funciones de gestión de directorios
    • app funciones especificas de Ink.Watercolor
      • pdb.tol funciones de la base de datos de pinturas
      • pag.tol funciones para generar páginas web Html
      • sed.tol semillas, templates, de páginas web Html
      • ftp.tol funciones para generar mandatos para hacer Ftp
      • xml.tol funciones históricas para sitemaps en Xml
      • alc.tol alchemy para la transformación de imágenes
      • ink.tol funciones auxiliares de InkWatercolor
    • inc.tol inclusión de los ficheros Tol básicos y de aplicación
  • agenda directorio destinado a albergar los ficheros de agendas de posts
    • chpphodb01.txt ejemplo con las 4 primeras obras artísticas que se incluyeron
  • web directorio destinado a las paginas web generadas automáticamente
    • common directorio de recursos comunes a todas las galerías
      • css directorio para ficheros de estilo
        • common.css fichero de estilo para las paginas Html del sitio web
      • seed trozos de código Html para construir templates
        • strseed.htm estructura básica de página Html de inkwatercolor.com
        • pi1lowseed.htm estructura para albergar información sobre una obra
        • pi4cntseed.htm estructura para albergar 4 pinturas en una página
      • src directorio para ficheros javascript
    • chppho directorio para la galería principal de Inkwatercolor
      • index.html ejemplo de página Html generada automáticamente
    • download directorio para material extra para descargas
      • chppho0129.jpg ejemplo de imagen de obra artística para descargar
      • chppho0143.jpg ejemplo de imagen de obra artística para descargar
    • sitemap.xml mapa del sitio web generado en Xml de forma automática
  • history archivo de registro histórico del programa Ink.Watercolor
  • ink_watercolor.pdf documento resumen de funciones del programa de generación Html

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

Tol