new command "parsestring" and friends

git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@7450 e016b1c5-ed68-44aa-a2f7-31cac88cffde
This commit is contained in:
Bukz
2013-04-03 22:28:39 +00:00
parent f8e3dbec68
commit d86afb077e
3 changed files with 90 additions and 0 deletions
+18
View File
@@ -135,6 +135,8 @@ docargument [N] [the index of the word] [] [0];
docexample [echo (at "zero one two three" 2)] [output: two];
docident [break] [Aborts a loop created with a 'loop', 'looplist' or 'while' command.];
docexample [loop i 10 [ if (= $i 4) [ break ]; echo $i]] [output: 0 1 2 3];
docident [breakparse] [Breaks out of a parsestring loop.];
docremark [Important: This command should only be used within the 3rd argument (the cubescript to execute) of parsestring.];
docident [c] [Adds color to a string.];
docargument [N] [color id] [0 min, 9 max] [0];
docexample [echo (c 3)Hello (c 0)world!] [Output: a red "Hello" and a green "world!"];
@@ -309,6 +311,16 @@ docexample [echo (modf 7.5 12.5)] [Output: 7.5];
docexample [echo (modf 17.5 12.5)] [Output: 5.0];
docident [numargs] [The number of arguments passed to the current alias];
docargument [V] [numargs] [ read-only];
docident [parsestring] [Loops through every character in the given string and executes the given block of cubescript on each iteration.];
docargument [S] [string] [string to parse] [0];
docargument [A] [string] [name of alias to use as iterator] [0];
docargument [C] [string] [cubescript to execute on each iteration] [0];
docargument [B] [integer] [non-zero to force backwards parse] [0];
docremark [Important: A secondary iterator alias (prefixed with a double underscore "__") is automatically created before each iteration that contains the character position data.];
docexample [parsestring "Hello world" iter [echo $iter]] [Uses echo on every character in the string: "Hello world"];
docexample [parsestring "Hello world" iter [echo (concatword "Char #" $__iter ": " $iter)]] [Uses echo on every character in the string: "Hello world" --- Also outputs the position of each character in the string.];
docexample [backwardsstring = []; parsestring "This will look interesting backwards." iter [backwardsstring = (concatword $backwardsstring $iter); if (= $__iter 0) [echo $backwardsstring]] 1] [Outputs: ".sdrawkcab gnitseretni kool lliw sihT"];
docexample [parsestring "abcdefghijklmnopqrstuvwxyz" iter [if (> $__iter 4) breakparse [echo $iter]]] [Example usage of the breakparse command. Uses echo on characters a through e, then breaks out of the parse.];
docident [persistidents] [Controls whether aliases defined afterwards will be saved (1) or not (0). This option is useful to keep saved.cfg free from unneeded clutter.];
docargument [B] [control option] [1...persistent, 0...not persistent] [0];
docexample [persistidents 0; foo = [ echo "bar"]] [foo will not be saved and has to be redefined when restarting AC.];
@@ -397,6 +409,12 @@ docexample [echo (tolower HELLO)] [Output: hello];
docident [toupper] [Converts a string to all uppercase characters.];
docargument [S] [a string] [] [0];
docexample [echo (toupper hello)] [Output: HELLO];
docident [trimAllUnnecessaryWhitespace] [Removes all unnecessary leading and trailing whitespace characters from the given string.];
docargument [S] [string] [string to modify] [0];
docexample [echo (trimAllUnnecessaryWhitespace " H e ll o w o r l d ")] [Outputs: "H e ll o w o r l d"];
docident [trimAllWhitespace] [Removes all whitespace characters from the given string.];
docargument [S] [string] [string to modify] [0];
docexample [echo (trimAllWhitespace " H e ll o w o r l d ")] [Outputs: Helloworld];
docident [while] [Loops the specified body while the condition evaluates to true.];
docargument [cond] [the condition] [the code evaluated before each iteration] [0];
docargument [body] [the body to execute on each iteration] [] [0];