|
List functions: thisThis library contains some Data Types: Text Item selector "[]": Text Glossary: text, text_valtext utilities, like white space clipping Operators: Boolean Or with Variable "||=" Operators: Bitwise Or with Variable "|=" Operators: Bitwise Or "|" Operators: Boolean Or "||"or splitting of Data Types: Text Item selector "[]": Text Glossary: text, text_valtext into List functions: words Shell Immediate Commands: wordswords.
List functions: thisThis Text functions: file Instructions: filefile is included in every distribution.
TEXT.vl
/*
authoritative Text functions: file Instructions: filefile: /pub/Develop/projects/vipsi/libs/Data Types: Text Item selector "[]": Text Glossary: text, text_valTEXT.vl
*/
Instructions: var How does VScript::Value() work?: Var*&var Data Types: Text Item selector "[]": Text Glossary: text, text_valTEXT.SpinAgain = 0
Instructions: var How does VScript::Value() work?: Var*&var Data Types: Text Item selector "[]": Text Glossary: text, text_valTEXT.SpinDelay = 0.1 // animations/sec
Instructions: var How does VScript::Value() work?: Var*&var Data Types: Text Item selector "[]": Text Glossary: text, text_valTEXT.SpinIndex = 1
Instructions: var How does VScript::Value() work?: Var*&var Data Types: Text Item selector "[]": Text Glossary: text, text_valTEXT.SpinCount = 0
Instructions: procproc Data Types: Text Item selector "[]": Text Glossary: text, text_valTEXT.SpinReset() { SpinCount=0 }
Instructions: procproc Data Types: Text Item selector "[]": Text Glossary: text, text_valTEXT.SpinWheel()
{
Flow control: if … thenif Numeric functions: nownow>=SpinAgain
SpinAgain = Numeric functions: nownow + SpinDelay
SpinIndex %= 4
SpinIndex += 1
Instructions: putput "|/-\\"[SpinIndex],"\b"
Flow control: if … then Flow control: try … thenthen
Flow control: returnreturn ++SpinCount
}
Instructions: procproc Data Types: Text Item selector "[]": Text Glossary: text, text_valTEXT.CropSpaces_R ( t )
{
Instructions: var How does VScript::Value() work?: Var*&var j = Numeric functions: countcount t
Flow control: do … loopdo Flow control: whilewhile j && t[j]<=" " j-- Flow control: do … looploop
Flow control: returnreturn t[to j]
}
Instructions: procproc Data Types: Text Item selector "[]": Text Glossary: text, text_valTEXT.CropSpaces_L ( t )
{
Instructions: var How does VScript::Value() work?: Var*&var j = 1
Flow control: do … loopdo Flow control: whilewhile j<=Numeric functions: countcount t && t[j]<=" " j++ Flow control: do … looploop
Flow control: returnreturn t[j to]
}
Instructions: procproc Data Types: Text Item selector "[]": Text Glossary: text, text_valTEXT.CropSpaces ( t )
{
Instructions: var How does VScript::Value() work?: Var*&var a=1, e=Numeric functions: countcount t
Flow control: do … loopdo Flow control: whilewhile e && t[e]<=" " e-- Flow control: do … looploop
Flow control: do … loopdo Flow control: whilewhile a<=e && t[a]<=" " a++ Flow control: do … looploop
Flow control: returnreturn t[a to e]
}
/* ---- Zerlege einen Data Types: Text Item selector "[]": Text Glossary: text, text_valText in Worte ----------------------------------
ein: "Ein Beispielsatz."
aus: { "","Ein"," ","Beispielsatz","." } // { gap, List functions: words Shell Immediate Commands: wordsword, gap, ... gap }
first Operators: Boolean And with Variable "&&=" Operators: Bitwise And with Variable "&=" Operators: Bitwise And "&" Operators: Boolean And "&&"and last gap are always present but may be "".
(( => Numeric functions: countcount result is always odd ))
"***" -> { "***" }
"" -> { "" }
"a" -> { "","a","" }
" a" -> { " ","a","" }
"a " -> { "","a"," " }
*/
Instructions: var How does VScript::Value() work?: Var*&var Data Types: Text Item selector "[]": Text Glossary: text, text_valTEXT.anf = "ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÜ" # "abcdefghijklmnopqrstuvwxyzäöü" # "#<"
Instructions: var How does VScript::Value() work?: Var*&var Data Types: Text Item selector "[]": Text Glossary: text, text_valTEXT.mid = "ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÜ" # "abcdefghijklmnopqrstuvwxyzäöü" # "0123456789" # "ß-_"
Instructions: var How does VScript::Value() work?: Var*&var Data Types: Text Item selector "[]": Text Glossary: text, text_valTEXT.fin = "ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÜ" # "abcdefghijklmnopqrstuvwxyzäöü" # "0123456789" # "ß_>"
Instructions: procproc Data Types: Text Item selector "[]": Text Glossary: text, text_valTEXT.SplitWordsNoTags ( Glossary: text_ref, text_vartext )
{
var result = {}
Data Types: Text Item selector "[]": Text Glossary: text, text_valtext = " " # Data Types: Text Item selector "[]": Text Glossary: text, text_valtext # " " // --> simlify Flow control: do … looploop
Instructions: var How does VScript::Value() work?: Var*&var wrd = 1, gap = 1 // wort == [wrd ... [gap
Instructions: var How does VScript::Value() work?: Var*&var len = Numeric functions: countcount Data Types: Text Item selector "[]": Text Glossary: text, text_valtext
Flow control: do … loopdo
// 1. gap:
wrd = gap
Flow control: do … loopdo // skip gap
Flow control: whilewhile ++wrd<=len
Flow control: untiluntil Numeric functions: findfind(Data Types: Text Item selector "[]": Text Glossary: text, text_valTEXT.anf,Data Types: Text Item selector "[]": Text Glossary: text, text_valtext[wrd])
Flow control: do … looploop
// wrd -> word_anfang
result ##= Data Types: Text Item selector "[]": Text Glossary: text, text_valtext[gap to wrd-1]
Flow control: whilewhile wrd <= len
// 2. List functions: words Shell Immediate Commands: wordsword:
gap = wrd
Flow control: do … loopdo // skip List functions: words Shell Immediate Commands: wordsword
Flow control: whilewhile ++gap<=len
Flow control: whilewhile Numeric functions: findfind(Data Types: Text Item selector "[]": Text Glossary: text, text_valTEXT.mid,Data Types: Text Item selector "[]": Text Glossary: text, text_valtext[gap])
Flow control: do … looploop
Flow control: if … thenif !Numeric functions: findfind( Data Types: Text Item selector "[]": Text Glossary: text, text_valTEXT.fin,Data Types: Text Item selector "[]": Text Glossary: text, text_valtext[gap-1] ) gap--
Flow control: if … thenelif gap<=len && Numeric functions: findfind(Data Types: Text Item selector "[]": Text Glossary: text, text_valTEXT.fin,Data Types: Text Item selector "[]": Text Glossary: text, text_valtext[gap]) gap++ Flow control: if … then Flow control: try … thenthen
// gap -> gap_anfang
result ##= Data Types: Text Item selector "[]": Text Glossary: text, text_valtext[wrd to gap-1]
Flow control: do … looploop
Instructions: var How does VScript::Value() work?: Var*&var n = Numeric functions: countcount result
result[1] = result[1][2 to]
result[n] = result[n][to Numeric functions: countcount(result[n])-1 ]
Flow control: returnreturn result
}
/* ---- Zerlege einen Data Types: Text Item selector "[]": Text Glossary: text, text_valText in Worte ----------------------------------
html-Tags: werden als Wort-Separator behandelt
Text functions: link Instructions: linkLinks: <a>...</a> Text functions: link Instructions: linkLinks werden als ein einziges Wort behandelt
=> Verhindert den Einbau von automatischen Text functions: link Instructions: linkLinks in den Text functions: link Instructions: linkLink!
ein: "Ein <b>Beispielsatz</b>."
aus: { "","Ein"," ","<b>","","Beispielsatz","","</b>","." } // { sep, List functions: words Shell Immediate Commands: wordsword, sep, ... sep }
*/
Instructions: procproc Data Types: Text Item selector "[]": Text Glossary: text, text_valTEXT.SplitIntoWords ( Glossary: text_ref, text_vartext )
{
var result = { "" }
// Text functions: convert Instructions: convertconvert Data Types: Text Item selector "[]": Text Glossary: text, text_valtext from html // " -> " etc.; verändert Textlänge + Textinhalt!
// da sollte ggf. die anker/link-Erzeugung _vor_ der html-konvertierung stattfinden!
Instructions: procproc append_to_result ( Glossary: text_ref, text_vartext )
{
var r = Numeric functions: countcount result
result ##= Data Types: Text Item selector "[]": Text Glossary: text, text_valTEXT.SplitWordsNoTags( Data Types: Text Item selector "[]": Text Glossary: text, text_valtext )
result[r] #= result[r+1] // List functions: join Instructions: joinjoin gaps
Instructions: deldel result[r+1]
}
Flow control: do … loopdo
Instructions: var How does VScript::Value() work?: Var*&var i = Numeric functions: findfind(Data Types: Text Item selector "[]": Text Glossary: text, text_valtext,"<") Flow control: whilewhile i
Instructions: var How does VScript::Value() work?: Var*&var j = Numeric functions: findfind(Data Types: Text Item selector "[]": Text Glossary: text, text_valtext,">",i) Flow control: whilewhile j
i = Numeric functions: rfindrfind(Data Types: Text Item selector "[]": Text Glossary: text, text_valtext,"<",j)
append_to_result( Data Types: Text Item selector "[]": Text Glossary: text, text_valtext[to i-1] ) // append Data Types: Text Item selector "[]": Text Glossary: text, text_valtext before html tag
Instructions: var How does VScript::Value() work?: Var*&var tag = Data Types: Text Item selector "[]": Text Glossary: text, text_valtext[i to j] // Flow control: if … then Flow control: try … thenthe tag "<xy>"
Data Types: Text Item selector "[]": Text Glossary: text, text_valtext = Data Types: Text Item selector "[]": Text Glossary: text, text_valtext[j+1 Text functions: stringto] // text after tag
Flow control: if … thenif j-i >= 160 // unlikely to be really a tag
append_to_result( tag ) // "<" Operators: Boolean And with Variable "&&=" Operators: Bitwise And with Variable "&=" Operators: Bitwise And "&" Operators: Boolean And "&&"and ">" will be handled as sep's
Flow control: nextnext
Flow control: if … then Flow control: try … thenthen
Instructions: var How does VScript::Value() work?: Var*&var lctag = Text functions: lowerstrlowerstr(tag)
Instructions: var How does VScript::Value() work?: Var*&var j = 1 + (lctag[2]=="/")
Flow control: do … loopdo Flow control: whilewhile lctag[++j]>="a" Flow control: do … looploop
Instructions: var How does VScript::Value() work?: Var*&var id = lctag[2 to j-1] // id := "a" Operators: Boolean Or with Variable "||=" Operators: Bitwise Or with Variable "|=" Operators: Bitwise Or "|" Operators: Boolean Or "||"or "/a" Operators: Boolean Or with Variable "||=" Operators: Bitwise Or with Variable "|=" Operators: Bitwise Or "|" Operators: Boolean Or "||"or "pre" etc.
Flow control: if … thenif !Numeric functions: findfind(HTML.TagsAny," "#id#" ") // no html tag
append_to_result( tag ) // handle '<' Operators: Boolean And with Variable "&&=" Operators: Bitwise And with Variable "&=" Operators: Bitwise And "&" Operators: Boolean And "&&"and '>' as sep's
Flow control: nextnext
Flow control: if … then Flow control: try … thenthen
// html tag:
Flow control: if … thenif id!="a" || !Numeric functions: findfind(lctag,"href=") // Operators: Bitwise Not "~" Operators: Boolean Negation "!"not a <a href=""> tag ((aka 'Text functions: link Instructions: linklink'))
result ##= tag ## "" // preserve entire html tag as List functions: words Shell Immediate Commands: wordsword
Flow control: nextnext
Flow control: if … then Flow control: try … thenthen
// <a href=""> ... </a> must be kept as entity:
i = Numeric functions: findfind(Text functions: lowerstrlowerstr(Data Types: Text Item selector "[]": Text Glossary: text, text_valtext),"</a>")
Flow control: if … thenif i
tag #= Data Types: Text Item selector "[]": Text Glossary: text, text_valtext[to i+3]
Data Types: Text Item selector "[]": Text Glossary: text, text_valtext = Data Types: Text Item selector "[]": Text Glossary: text, text_valtext[i+4 to]
Flow control: if … then Flow control: try … thenelse
Numeric functions: log Numeric functions: loge Instructions: loglog Constants: nlnl, "'</a>' missing: ", tag, " "
Flow control: if … then Flow control: try … thenthen
result ##= tag ## ""
Flow control: do … looploop
append_to_result( Data Types: Text Item selector "[]": Text Glossary: text, text_valtext )
Flow control: returnreturn result
}
Instructions: procproc Data Types: Text Item selector "[]": Text Glossary: text, text_valTEXT.JoinText ( Data Types: Lists and arrays Item selector "[]": Lists Glossary: list, list_valliste, * ) // opt. Separatorsseparator
{
Flow control: if … thenif Numeric functions: countcount List functions: localslocals>1
Flow control: if … thenif Numeric functions: countcount Data Types: Lists and arrays Item selector "[]": Lists Glossary: list, list_valliste == 0 Flow control: returnreturn "" Flow control: if … then Flow control: try … thenthen // dann ex. Data Types: Lists and arrays Item selector "[]": Lists Glossary: list, list_valliste[1] nicht!
Instructions: renamerename List functions: localslocals[2] = "sep"
Instructions: var How does VScript::Value() work?: Var*&var z = Data Types: Lists and arrays Item selector "[]": Lists Glossary: list, list_valliste[1]
Data Types: Lists and arrays Item selector "[]": Lists Glossary: list, list_valliste = sep # Data Types: Lists and arrays Item selector "[]": Lists Glossary: list, list_valliste // operation on whole Data Types: Lists and arrays Item selector "[]": Lists Glossary: list, list_vallist!
Data Types: Lists and arrays Item selector "[]": Lists Glossary: list, list_valliste[1] = z
Flow control: if … then Flow control: try … thenthen
Instructions: var How does VScript::Value() work?: Var*&var Data Types: Text Item selector "[]": Text Glossary: text, text_valtext = ""
Instructions: var How does VScript::Value() work?: Var*&var i = 0
Flow control: do … loopdo
Flow control: whilewhile ++i <= Numeric functions: countcount Data Types: Lists and arrays Item selector "[]": Lists Glossary: list, list_valliste
Data Types: Text Item selector "[]": Text Glossary: text, text_valtext #= Data Types: Lists and arrays Item selector "[]": Lists Glossary: list, list_valliste[i]
Flow control: do … looploop
Flow control: returnreturn Data Types: Text Item selector "[]": Text Glossary: text, text_valtext
}
/* ---- Vipsi command syntax: Identifiers (names) Identifiers, names Operators: Make Identifier "@" Text functions: name Glossary: Name, IdentifierNamen normalisieren ---------------
ein: separierte Worte wie von Data Types: Text Item selector "[]": Text Glossary: text, text_valTEXT.SplitIntoWords()
ein: { "ein", "Anker" }
aus: "ein_ank"
*/
Instructions: procproc Data Types: Text Item selector "[]": Text Glossary: text, text_valTEXT.NormalizeName ( Glossary: list_ref, list_varliste )
{
var result = ""
Instructions: var How does VScript::Value() work?: Var*&var i = 0
Flow control: do … loopdo
Flow control: whilewhile ++i <= Numeric functions: countcount Glossary: list_ref, list_varliste
var List functions: words Shell Immediate Commands: wordsword = Text functions: lowerstrlowerstr(Data Types: Lists and arrays Item selector "[]": Lists Glossary: list, list_valliste[i])
// Flow control: if … thenif i!=1 && i!=Numeric functions: countcount(Data Types: Lists and arrays Item selector "[]": Lists Glossary: list, list_valliste) && Numeric functions: findfind(" der die das a Flow control: if … then Flow control: try … thenthe "," "#word#" ")
// Flow control: nextnext
// Flow control: if … then Flow control: try … thenthen
Flow control: if … thenif Numeric functions: countcount List functions: words Shell Immediate Commands: wordsword>=3 && Numeric functions: findfind( " er en em es ", " "#rightstr(List functions: words Shell Immediate Commands: wordsword,2)#" " )
List functions: words Shell Immediate Commands: wordsword = List functions: words Shell Immediate Commands: wordsword[to Numeric functions: countcount List functions: words Shell Immediate Commands: wordsword -2]
Flow control: if … thenelif Numeric functions: countcount List functions: words Shell Immediate Commands: wordsword>=3 && Numeric functions: findfind( "es", Text functions: rightstrrightstr(List functions: words Shell Immediate Commands: wordsword,1) )
List functions: words Shell Immediate Commands: wordsword = List functions: words Shell Immediate Commands: wordsword[to Numeric functions: countcount List functions: words Shell Immediate Commands: wordsword -1]
Flow control: if … then Flow control: try … thenthen
result #= "_" # List functions: words Shell Immediate Commands: wordsword
Flow control: do … looploop
Flow control: returnreturn result[2 to]
}
/* ---- remove odd items from Data Types: Lists and arrays Item selector "[]": Lists Glossary: list, list_vallist ---------------------
-> removes Flow control: if … then Flow control: try … thenthe sep's from a split-into-words Data Types: Lists and arrays Item selector "[]": Lists Glossary: list, list_vallist
*/
Instructions: procproc Data Types: Text Item selector "[]": Text Glossary: text, text_valTEXT.RemoveOddItems ( Glossary: list_ref, list_varliste )
{
var i=0
Flow control: do … loopdo
Flow control: whilewhile ++i <= Numeric functions: countcount Data Types: Lists and arrays Item selector "[]": Lists Glossary: list, list_valliste
Instructions: deldel Data Types: Lists and arrays Item selector "[]": Lists Glossary: list, list_valliste[i]
Flow control: do … looploop
Flow control: returnreturn Data Types: Lists and arrays Item selector "[]": Lists Glossary: list, list_valliste
}
/* for vipsi < 0.8.8 */
/*
Flow control: try … thentry
Instructions: procproc Text functions: spacestrspacestr(len)
{
Instructions: var How does VScript::Value() work?: Var*&var spc = " "
Flow control: do … loopdo Flow control: whilewhile Numeric functions: countcount spc < len spc #= spc[to len-count spc] Flow control: do … looploop
Flow control: returnreturn spc[to len]
}
Flow control: if … then Flow control: try … thenthen
*/
Flow control: end Shell Immediate Commands: exit, quit, endend 0
| |