//////////////////////////////////////////////////////////////// // // ULTIMATE LIBRARY : // // This file defines all the new major functions for UCE. // // //////////////////////////////////////////////////////////////// // // Made by [Fr]enchBadPunk - 2011 - Public Domain // //////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////// // // NEW FUNCTIONS : // // charset ; _charsetindex ; _charsetat // // charisuppercaseletter ; charislowercaseletter // charisletter ; charisnumber ; charisother // strisuppercase ; strislowercase // // charswitchcase ; charuppercase ; charlowercase // strswitchcase ; struppercase ; strlowercase // // Extended strings functions : // strstrcount ; strstrat ; strreplacechar ; strreplaceat // strrepeat // //////////////////////////////////////////////////////////////// _charset = [ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ ] //95 = brkln ; 96 = tab charset = $_charset _charsetindex = [ if (&& (> $numargs 0) (!=s $arg1 "")) [ result (strstr $_charset $arg1) ] [ result -1 ] ] _charsetat = [ if (|| (< $arg1 0) (< $numargs 1)) [ _charsetat_i = 0 ] [ if (> $arg1 (- (strlen $_charset) 1)) [ _charsetat_i = (- (strlen $_charset) 1) ] [ _charsetat_i = $arg1 ] ] result (substr $_charset $_charsetat_i 1) ( _charsetat_i = ) ] //////////////////////////////////////////////////////////////// isexist = [ ? (strlen $arg1) 1 0 ] isempty = [ ? (strlen $arg1) 1 0 ] isstring = [ if (! (=f $arg1 0)) [ _isstring_tmp = result 0A // It'a a number ! ] [ // Test spaces before "-" _isstring_tmp = (substr $arg1 0 (strstr $arg1 "-")) if (> (strlen $_isstring_tmp) 0) [ _isstring_tmp2 = 0 loop _isstring_count (strlen $_isstring_tmp) [ if (!=s (substr $_isstring_tmp $_isstring_count 1) " ") [ _isstring_tmp2 = 1 ] ] _isstring_count = if (= $_isstring_tmp2 1) [ _isstring_tmp2 = _isstring_tmp = result 1B // It's a string ] ] _isstring_tmp2 = // Take all afer the "-" _isstring_tmp = (substr $arg1 (+ (strstr $arg1 "-") 1)) if (= (strlen $_isstring_tmp) 0) [ _isstring_tmp = result 1C // It's a string ] [ if (= (strlen $_isstring_tmp) 1) [ if (=s $_isstring_tmp "0") [ _isstring_tmp = result 0D // It's a number ] [ _isstring_tmp = result 1E // It's a string ] ] [ // Remove all "0" _isstring_tmp = (strreplace $_isstring_tmp "0" "") if (= (strlen $_isstring_tmp) 0) [ _isstring_tmp = result 0F // It's a number ] [ if (= (strlen $_isstring_tmp) 1) [ if (|| (=s $_isstring_tmp ".") (=s $_isstring_tmp " ")) [ _isstring_tmp = result 0G // It's a number ] [ _isstring_tmp = result 1H // It's a string ] ] [ _isstring_tmp = result 1I // It's a string ] ] ] ] ] ] isstr = [ ] ischar = [ ] isnum = [ ] islist = [ ? (> (listlen $arg1) 1) 1 0 ] isspcstrlst = [ if (islist $arg1) [ if (&& (strcmp (substr $arg1 0 1) "^"") ( strcmp (substr $arg1 (+ 2 (strlen (strstr $arg1 (at $arg1 0)) )) 1) "^"") ) [ result 1 ] ] [ result 0 ] ] [ result 0 ] //////////////////////////////////////////////////////////////// charisuppercaseletter = [ ? (&& (>=s (substr $arg1 0 1) (_charsetat 33)) (<=s (substr $arg1 0 1) (_charsetat 58))) 1 0 ] charislowercaseletter = [ ? (&& (>=s (substr $arg1 0 1) (_charsetat 65)) (<=s (substr $arg1 0 1) (_charsetat 90))) 1 0 ] charisletter = [ ? (|| (= (charislowercaseletter (substr $arg1 0 1)) 1) (= (charisuppercaseletter (substr $arg1 0 1)) 1)) 1 0 ] charisnumber = [ ? (&& (>=s (substr $arg1 0 1) (_charsetat 16)) (<=s (substr $arg1 0 1) (_charsetat 25))) 1 0 ] charisother = [ ? (&& (= (charisnumber (substr $arg1 0 1)) 0) (= (charisletter (substr $arg1 0 1)) 0)) 1 0 ] //////////////////////////////////////////////////////////////// strisuppercase = [ if (&& (> $numargs 0) (!=s $arg1 "")) [ _strisuppercase_result = 1 loop _strisuppercase_i (strlen $arg1) [ if (= (charislowercase (substr $arg1 $_strisuppercase_i 1)) 1) [ _strisuppercase_result = 0 ] ] _strisuppercase_i = result $_strisuppercase_result ] [ result 0 ] ( _strisuppercase_i = _strisuppercase_result = ) ] strislowercase = [ _strislowercase_result = 1 loop _strislowercase_i (strlen $arg1) [ if (= (charisuppercase (substr $arg1 $_strislowercase_i 1)) 1) [ _strislowercase_result = 0 ] ] _strislowercase_i = result $_strislowercase_result ( _strislowercase_i = _strislowercase_result = ) ] //////////////////////////////////////////////////////////////// charswitchcase = [ if (> $numargs 0) [ if (= (charisletter (substr $arg1 0 1)) 1) [ if (= (charisuppercaseletter (substr $arg1 0 1)) 1) [ result (_charsetat (+ (_charsetindex (substr $arg1 0 1)) 32)) ] [ result (_charsetat (- (_charsetindex (substr $arg1 0 1)) 32)) ] ] [ result $arg1 ] ] [ result "" ] ] charuppercase = [ if (= (charislowercaseletter (substr $arg1 0 1)) 1) [ result (_charsetat (- (_charsetindex (substr $arg1 0 1)) 32)) ] [ if (> $numargs 0) [ result $arg1 ] [ result "" ] ] ] charlowercase = [ if (= (charisuppercaseletter (substr $arg1 0 1)) 1) [ result (_charsetat (+ (_charsetindex (substr $arg1 0 1)) 32)) ] [ if (> $numargs 0) [ result $arg1 ] [ result "" ] ] ] strswitchcase = [ if (> $numargs 0) [ _strswitchcase_result = "" loop _strswitchcase_i (strlen $arg1) [ _strswitchcase_result = (concatword $_strswitchcase_result ( charswitchcase (substr $arg1 $_strswitchcase_i 1))) ] result $_strswitchcase_result ] [ result "" ] ( _strswitchcase_i = _strswitchcase_result = ) ] struppercase = [ if (> $numargs 0) [ _struppercase_result = "" loop _struppercase_i (strlen $arg1) [ _struppercase_result = (concatword $_struppercase_result (charuppercase (substr $arg1 $_struppercase_i 1))) ] result $_struppercase_result ] [ result "" ] ( _struppercase_i = _struppercase_result = ) ] strlowercase = [ if (> $numargs 0) [ _strlowercase_result = "" loop _strlowercase_i (strlen $arg1) [ _strlowercase_result = (concatword $_strlowercase_result (charlowercase (substr $arg1 $_strlowercase_i 1))) ] result $_strlowercase_result ] [ result "" ] ( _strlowercase_i = _strlowercase_result = ) ] //////////////////////////////////////////////////////////////// // // EXTENDED STRINGS FUNCTIONS : // // strstrcount var string_to_count ; Ret. the count number // strstrat var str_to_search [index] ; Ret. : the start char pos. // strreplacechar var pos new_str // strreplaceat var str_to_search [new_str] [index] ; Ret. a str. // strrepeat var [num_of_repeat] ; Ret. a string // //////////////////////////////////////////////////////////////// strstrcount = [ // $arg1 : The string var // $arg2 : The string to count if (= $numargs 0) [ _strstrcount_tmp = "" ] [ _strstrcount_tmp = $arg1 ] if (&& (> $numargs 1) (!=s $arg2 "")) [ _strstrcount_count = 0 while [ (!=s $_strstrcount_tmp "") ] [ if (= (strstr $_strstrcount_tmp $arg2) -1) [ _strstrcount_tmp = "" ] [ _strstrcount_count = (+ $_strstrcount_count 1) _strstrcount_tmp = (substr $_strstrcount_tmp (+ (strstr $_strstrcount_tmp $arg2) (strlen $arg2))) ] ] result $_strstrcount_count ] [ result -1 ] ( _strstrcount_count = _strstrcount_tmp = ) ] strstrat = [ // $arg1 : The string var // $arg2 : The string to find // $arg3 : The index of the found string (start at 0) // Return the position of the first char of this string in the string var. // (e.g. : a = "012A012B012C012D" ; strstrat $a 2 <= that return 8 if (= $numargs 0) [ _strstrat_tmp = "" ] [ _strstrat_tmp = $arg1 ] if (< $numargs 3) [ _strstrat_index = 0 ] [ _strstrat_index = $arg3 ] if (&& (> $numargs 1) (!=s $arg2 "")) [ _strstrat_count = 0 _strstrat_pos = 0 _strstrat_result = -1 while [ (!=s $_strstrat_tmp "") ] [ if (= (strstr $_strstrat_tmp $arg2) -1) [ _strstrat_tmp = "" ] [ if (= $_strstrat_count $_strstrat_index) [ // Return the result _strstrat_result = (+ $_strstrat_pos (strstr $_strstrat_tmp $arg2)) _strstrat_tmp = "" ] [ _strstrat_pos = (+ $_strstrat_pos (+ (strstr $_strstrat_tmp $arg2) (strlen $arg2))) _strstrat_tmp = (substr $_strstrat_tmp (+ (strstr $_strstrat_tmp $arg2) (strlen $arg2))) ] _strstrat_count = (+ $_strstrat_count 1) ] ] result $_strstrat_result ] [ result -1 ] ( _strstrat_index = _strstrat_count = _strstrat_tmp = _strstrat_pos = _strstrat_result = ) ] strreplacechar = [ // $arg1 : The string var // $arg2 : The position of the char to replace // $arg3 : The replacement string // e.g : a = "01234" ; strreplaceat $a 2 "ab" <= return "01ab34" if (> $numargs 0) [ if (!=s $arg1 "") [ if (> $numargs 1) [ if (< $numargs 3) [ _strreplacechar_arg3 = "" ] [ _strreplacechar_arg3 = $arg3 ] result (format [%1%2%3] ( substr $arg1 0 $arg2 ) $_strreplacechar_arg3 ( substr $arg1 (+ $arg2 1))) ] [ result "" ] ] [ if (= $numargs 3) [ if (!=s $arg3 "") [ result $arg3 ] [ result "" ] ] [ result "" ] ] ] [ result "" ] ( _strreplacechar_arg3 = ) ] strreplaceat = [ // $arg1 : The string var // $arg2 : The string to find // $arg3 : The replacement string // $arg4 : The index of string finding (start at 0) // e.g : a = "012012012" ; strreplaceat $a "12" "ab" 1 <= return "0120ab012" _strreplaceat_result = "" if (< $numargs 1) [ _strreplaceat_arg1 = "" ] [ _strreplaceat_arg1 = $arg1 ] if (< $numargs 2) [ _strreplaceat_arg2 = "" ] [ _strreplaceat_arg2 = $arg2 ] if (< $numargs 3) [ _strreplaceat_arg3 = "" ] [ _strreplaceat_arg3 = $arg3 ] if (< $numargs 4) [ _strreplaceat_arg4 = 0 ] [ _strreplaceat_arg4 = $arg4 ] if (&& (>= $numargs 2) (&& (!=s $_strreplaceat_arg1 "") (!=s $_strreplaceat_arg2 ""))) [ _strreplaceat_result = (format "%1%2%3" ( substr $_strreplaceat_arg1 0 (strstrat $_strreplaceat_arg1 $_strreplaceat_arg2 $_strreplaceat_arg4) ) $arg3 ( substr $_strreplaceat_arg1 (+ (+ (strstrat $_strreplaceat_arg1 $_strreplaceat_arg2 $_strreplaceat_arg4) (strlen $_strreplaceat_arg4)) 1) ) ) ] [ if (&& (= $numargs 2) (!=s $_strreplaceat_arg2 "")) [ _strreplaceat_result = $_strreplaceat_arg2 ] [ _strreplaceat_result = $_strreplaceat_arg1 ] ] result $_strreplaceat_result ( _strreplaceat_arg1 = _strreplaceat_arg2 = _strreplaceat_arg3 = _strreplaceat_arg4 = _strreplaceat_result = ) ] strrepeat = [ // $arg1 : The string to repeat // $arg2 : The number of repetition if (= $numargs 0) [ result "" ] if (= $numargs 1) [ result $arg1 ] [ if (= $numargs 2) [ _strrepeat_tmp = "" loop _strrepeat_i $arg2 [ _strrepeat_tmp = (concatword $_strrepeat_tmp $arg1) ] result $_strrepeat_tmp ( _strrepeat_i = _strrepeat_tmp = ) ] ] ] //////////////////////////////////////////////////////////////// // Existing internal commands : // listlen $list => number of element (starting at 1 !) // listdel $list $str => newlist // indexof $list $str => index_num // looplist var $list [ body ($var is the index) ] // listfind var $list [ body ($var is the index) ] //myaddfunc = [ result (concat $arg1 (format ["%1"] $arg2) ) ] // New ListAdd function listadd = [ // $arg1 : list // $arg2 : content // [$arg3] : add content (0) or like a spaced string (1) // [$arg4] : before (index by default) // [$arg5] : before is index (0) or a content to find (1) case $numargs 2 [ @result (concat $arg1 $arg2) ] 3 [ if (= $arg3 1) [ @@result (concat $arg1 (format ["%1"] $arg2)) ] [ @@result (concat $arg1 $arg2) ] ] 4 [ _listadd_tmp = "" loop _listadd_i $arg1 [ if (= $_listadd_i ($arg4)) _listadd_tmp ] @result $_listadd_tmp _listadd_tmp = _listadd_i = ] 5 [ ] [ // Else @result "" ] ] listaddbefore = [ result ( listadd $arg1 $arg2 0 $arg3) ] listaddbeforeat = [ result ( listadd $arg1 $arg2 0 $arg3 1) ] listaddstr = [ result ( listadd $arg1 $arg2 1) ] listaddstrbefore = [ result ( listadd $arg1 $arg2 1 $arg3) ] listaddstrbeforeat = [ result ( listadd $arg1 $arg2 1 $arg3 1) ] listclear = [ $arg1 = ] // $arg1 is a list - Use without "$" : /listclear listname //myaddfunc = [ result (concat $arg1 (format ["%1"] $arg2) ) ] //myaddfunc = [$arg1 = (concat (getalias $arg1) (format ["%1"] $arg2))] //append = [$arg1 = (concat (getalias $arg1) $arg2)] //////////////////////////////////////////////////////////////// // // UNINSTALL // //////////////////////////////////////////////////////////////// ucelib_uninstall = [ _charset = charset = _charsetindex = _charsetat = _charsetat_i = charisuppercaseletter = charislowercaseletter = charisletter = charisnumber = charisother = strisuppercase = _strisuppercase_i = _strisuppercase_result = strislowercase = _strislowercase_i = _strislowercase_result = charswitchcase = charuppercase = charlowercase = strswitchcase = _strswitchcase_i = _strswitchcase_result = struppercase = _struppercase_i = _struppercase_result = strlowercase = _strlowercase_result = _strlowercase_i = strstrcount = _strstrcount_count = _strstrcount_tmp = strstrat = _strstrat_index = _strstrat_count = _strstrat_tmp = _strstrat_pos = _strstrat_result = strreplacechar = strreplaceat = _strreplaceat_arg1 = _strreplaceat_arg2 = _strreplaceat_arg3 = _strreplaceat_arg4 = _strreplaceat_result = strrepeat = _strrepeat_tmp = ]