//////////////////////////////////////////////////////////////// // // 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 : // strinvert ; strstrcount ; strstrrev ; strstrat // strreplacechar ; strreplaceat // strrepeat ; loopstr ; echoo // //////////////////////////////////////////////////////////////// // New function : // rainbowiz $text [rnd] : Return rainbowized string. // if the arg [rnd] is present, do it with randome colors. rainbowiz = [ if (> $numargs 0) [ _rainbowiz_result = "" loop _rainbowiz_count (strlen $arg1) [ _rainbowiz_result = (format "%1^f%2%3" $_rainbowiz_result (? (> $numargs 1) (rnd 8) (mod $_rainbowiz_count 8)) (substr $arg1 $_rainbowiz_count 1)) ] result $_rainbowiz_result ( _rainbowiz_count = _rainbowiz_result = ) ] [ result "" ] ] _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 = ) ] //////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////// 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 : // // strinvert var ; Ret. the inverted string // strstrcount var string_to_count ; Ret. the count number // strstrrev var str_to_search ; Ret. the start pos. from the end // 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 // //////////////////////////////////////////////////////////////// strinvert = [ _strinvert_tmp = "" loop i (strlen $arg1) [ _strinvert_tmp = (concatword $_strinvert_tmp ( substr $arg1 (- (- (strlen $arg1) 1) $i) 1 )) ] result $_strinvert_tmp ( _strinvert_tmp = ) ] 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 = ) ] strstrrev = [ // $arg1 : a string // $arg2 : the string to find // Return the position of the find string starting at the end. _strstrrev_tmp = "" _strstrrev_result = -1 loop i (strlen $arg1) [ _strstrrev_tmp = (concatword (substr $arg1 (- (- (strlen $arg1) 1) $i) 1) $_strstrrev_tmp) if (&& (= $_strstrrev_result -1) (!= (strstr $_strstrrev_tmp $arg2) -1)) [ _strstrrev_result = (- (- (strlen $arg1) 1) $i) ] ] result $_strstrrev_result ( _strstrrev_tmp = ; _strstrrev_result = ) ] 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 = ) ] ] ] loopstr = [ loop i (strlen $arg2) [ @@$arg1 = (substr $arg2 $i 1) do $arg3 ] @@$arg1 = ] echoo = [ if (!=s $arg1 "") [ clearconsole ] _echoo_tmp = $arg1 while [ (!=s $_echoo_tmp "") ] [ echo (substr $_echoo_tmp 1 (* (divf 1 $conscale) 53)) _echoo_tmp = (substr $_echoo_tmp (* (divf 1 $conscale) 53)) ] ( _echoo_tmp = ) ] //////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////// // // 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 = strinvert = _strinvert_tmp = strstrcount = _strstrcount_count = _strstrcount_tmp = strstrat = _strstrat_index = _strstrat_count = _strstrat_tmp = _strstrat_pos = _strstrat_result = strstrrev _strstrrev_tmp = _strstrrev_result = strreplacechar = strreplaceat = _strreplaceat_arg1 = _strreplaceat_arg2 = _strreplaceat_arg3 = _strreplaceat_arg4 = _strreplaceat_result = strrepeat = _strrepeat_tmp = ]