diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-07-18 15:22:49 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-07-18 15:22:49 -0700 |
commit | 762b099ef6c6ad5b6b61d29e473baa6df8d64ab9 (patch) | |
tree | 8075befbcc8ef2784616c4937793ebed9d21123d /html/060string.mu.html | |
parent | 614ea44bc2708a687ba10b162a6dc70e48dfac59 (diff) | |
download | mu-762b099ef6c6ad5b6b61d29e473baa6df8d64ab9.tar.gz |
1818
Diffstat (limited to 'html/060string.mu.html')
-rw-r--r-- | html/060string.mu.html | 77 |
1 files changed, 28 insertions, 49 deletions
diff --git a/html/060string.mu.html b/html/060string.mu.html index eb98cd88..a78e7413 100644 --- a/html/060string.mu.html +++ b/html/060string.mu.html @@ -35,7 +35,7 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="Comment"># Some useful helpers for dealing with strings.</span> <span class="muRecipe">recipe</span> string-equal [ - <span class="Constant">new-default-space</span> + <span class="Constant">local-scope</span> a:address:array:character<span class="Special"> <- </span><span class="Constant">next-ingredient</span> a-len:number<span class="Special"> <- </span>length a:address:array:character/deref b:address:array:character<span class="Special"> <- </span><span class="Constant">next-ingredient</span> @@ -138,9 +138,8 @@ container buffer [ ] <span class="muRecipe">recipe</span> new-buffer [ - <span class="Constant">new-default-space</span> -<span class="CommentedCode">#? $print default-space:address:array:location, [</span> -<span class="CommentedCode">#? ]</span> + <span class="Constant">local-scope</span> +<span class="CommentedCode">#? $print default-space:address:array:location, 10:literal/newline</span> result:address:buffer<span class="Special"> <- </span>new buffer:type len:address:number<span class="Special"> <- </span>get-address result:address:buffer/deref, length:offset len:address:number/deref<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> @@ -148,13 +147,12 @@ container buffer [ capacity:number, found?:boolean<span class="Special"> <- </span><span class="Constant">next-ingredient</span> assert found?:boolean, <span class="Constant">[new-buffer must get a capacity argument]</span> s:address:address:array:character/deref<span class="Special"> <- </span>new character:type, capacity:number -<span class="CommentedCode">#? $print s:address:address:array:character/deref, [</span> -<span class="CommentedCode">#? ]</span> +<span class="CommentedCode">#? $print s:address:address:array:character/deref, 10:literal/newline</span> <span class="muControl">reply</span> result:address:buffer ] <span class="muRecipe">recipe</span> grow-buffer [ - <span class="Constant">new-default-space</span> + <span class="Constant">local-scope</span> in:address:buffer<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Comment"># double buffer size</span> x:address:address:array:character<span class="Special"> <- </span>get-address in:address:buffer/deref, data:offset @@ -177,7 +175,7 @@ container buffer [ ] <span class="muRecipe">recipe</span> buffer-full? [ - <span class="Constant">new-default-space</span> + <span class="Constant">local-scope</span> in:address:buffer<span class="Special"> <- </span><span class="Constant">next-ingredient</span> len:number<span class="Special"> <- </span>get in:address:buffer/deref, length:offset s:address:array:character<span class="Special"> <- </span>get in:address:buffer/deref, data:offset @@ -188,7 +186,7 @@ container buffer [ <span class="Comment"># in:address:buffer <- buffer-append in:address:buffer, c:character</span> <span class="muRecipe">recipe</span> buffer-append [ - <span class="Constant">new-default-space</span> + <span class="Constant">local-scope</span> in:address:buffer<span class="Special"> <- </span><span class="Constant">next-ingredient</span> c:character<span class="Special"> <- </span><span class="Constant">next-ingredient</span> len:address:number<span class="Special"> <- </span>get-address in:address:buffer/deref, length:offset @@ -208,13 +206,10 @@ container buffer [ in:address:buffer<span class="Special"> <- </span>grow-buffer in:address:buffer <span class="Delimiter">}</span> s:address:array:character<span class="Special"> <- </span>get in:address:buffer/deref, data:offset -<span class="CommentedCode">#? $print [array underlying buf: ], s:address:array:character, [ </span> -<span class="CommentedCode">#? ] #? 1</span> -<span class="CommentedCode">#? $print [index: ], len:address:number/deref, [ </span> -<span class="CommentedCode">#? ] #? 1</span> +<span class="CommentedCode">#? $print [array underlying buf: ], s:address:array:character, 10:literal/newline</span> +<span class="CommentedCode">#? $print [index: ], len:address:number/deref, 10:literal/newline</span> dest:address:character<span class="Special"> <- </span>index-address s:address:array:character/deref, len:address:number/deref -<span class="CommentedCode">#? $print [storing ], c:character, [ in ], dest:address:character, [ </span> -<span class="CommentedCode">#? ] #? 1</span> +<span class="CommentedCode">#? $print [storing ], c:character, [ in ], dest:address:character, 10:literal/newline</span> dest:address:character/deref<span class="Special"> <- </span>copy c:character len:address:number/deref<span class="Special"> <- </span>add len:address:number/deref, <span class="Constant">1:literal</span> <span class="muControl">reply</span> in:address:buffer/same-as-ingredient:0 @@ -222,7 +217,7 @@ container buffer [ <span class="muScenario">scenario</span> buffer-append-works [ run [ - <span class="Constant">new-default-space</span> + <span class="Constant">local-scope</span> x:address:buffer<span class="Special"> <- </span>new-buffer <span class="Constant">3:literal</span> s1:address:array:character<span class="Special"> <- </span>get x:address:buffer/deref, data:offset x:address:buffer<span class="Special"> <- </span>buffer-append x:address:buffer, <span class="Constant">97:literal</span> <span class="Comment"># 'a'</span> @@ -230,20 +225,6 @@ container buffer [ x:address:buffer<span class="Special"> <- </span>buffer-append x:address:buffer, <span class="Constant">99:literal</span> <span class="Comment"># 'c'</span> s2:address:array:character<span class="Special"> <- </span>get x:address:buffer/deref, data:offset 1:boolean/<span class="Special">raw <- </span>equal s1:address:array:character, s2:address:array:character -<span class="CommentedCode">#? $print s2:address:array:character, [</span> -<span class="CommentedCode">#? ]</span> -<span class="CommentedCode">#? $print 1060:number/raw, [</span> -<span class="CommentedCode">#? ]</span> -<span class="CommentedCode">#? $print 1061:number/raw, [</span> -<span class="CommentedCode">#? ]</span> -<span class="CommentedCode">#? $print 1062:number/raw, [</span> -<span class="CommentedCode">#? ]</span> -<span class="CommentedCode">#? $print 1063:number/raw, [</span> -<span class="CommentedCode">#? ]</span> -<span class="CommentedCode">#? $print 1064:number/raw, [</span> -<span class="CommentedCode">#? ]</span> -<span class="CommentedCode">#? $print 1065:number/raw, [</span> -<span class="CommentedCode">#? ]</span> 2:array:character/<span class="Special">raw <- </span>copy s2:address:array:character/deref <span class="Constant"> +buffer-filled</span> x:address:buffer<span class="Special"> <- </span>buffer-append x:address:buffer, <span class="Constant">100:literal</span> <span class="Comment"># 'd'</span> @@ -274,7 +255,7 @@ container buffer [ <span class="muScenario">scenario</span> buffer-append-handles-backspace [ run [ - <span class="Constant">new-default-space</span> + <span class="Constant">local-scope</span> x:address:buffer<span class="Special"> <- </span>new-buffer <span class="Constant">3:literal</span> x:address:buffer<span class="Special"> <- </span>buffer-append x:address:buffer, <span class="Constant">97:literal</span> <span class="Comment"># 'a'</span> x:address:buffer<span class="Special"> <- </span>buffer-append x:address:buffer, <span class="Constant">98:literal</span> <span class="Comment"># 'b'</span> @@ -291,7 +272,7 @@ container buffer [ <span class="Comment"># result:address:array:character <- integer-to-decimal-string n:number</span> <span class="muRecipe">recipe</span> integer-to-decimal-string [ - <span class="Constant">new-default-space</span> + <span class="Constant">local-scope</span> n:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Comment"># is it zero?</span> <span class="Delimiter">{</span> @@ -347,7 +328,7 @@ container buffer [ ] <span class="muRecipe">recipe</span> buffer-to-array [ - <span class="Constant">new-default-space</span> + <span class="Constant">local-scope</span> in:address:buffer<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Delimiter">{</span> <span class="Comment"># propagate null buffer</span> @@ -355,8 +336,7 @@ container buffer [ <span class="muControl">reply</span> <span class="Constant">0:literal</span> <span class="Delimiter">}</span> len:number<span class="Special"> <- </span>get in:address:buffer/deref, length:offset -<span class="CommentedCode">#? $print [size ], len:number, [ </span> -<span class="CommentedCode">#? ] #? 1</span> +<span class="CommentedCode">#? $print [size ], len:number, 10:literal/newline</span> s:address:array:character<span class="Special"> <- </span>get in:address:buffer/deref, data:offset <span class="Comment"># we can't just return s because it is usually the wrong length</span> result:address:array:character<span class="Special"> <- </span>new character:type, len:number @@ -408,7 +388,7 @@ container buffer [ <span class="Comment"># result:address:array:character <- string-append a:address:array:character, b:address:array:character</span> <span class="muRecipe">recipe</span> string-append [ - <span class="Constant">new-default-space</span> + <span class="Constant">local-scope</span> <span class="Comment"># result = new character[a.length + b.length]</span> a:address:array:character<span class="Special"> <- </span><span class="Constant">next-ingredient</span> a-len:number<span class="Special"> <- </span>length a:address:array:character/deref @@ -467,7 +447,7 @@ container buffer [ <span class="Comment"># replace underscores in first with remaining args</span> <span class="Comment"># result:address:array:character <- interpolate template:address:array:character, ...</span> <span class="muRecipe">recipe</span> interpolate [ - <span class="Constant">new-default-space</span> + <span class="Constant">local-scope</span> template:address:array:character<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Comment"># compute result-len, space to allocate for result</span> tem-len:number<span class="Special"> <- </span>length template:address:array:character/deref @@ -482,8 +462,7 @@ container buffer [ result-len:number<span class="Special"> <- </span>subtract result-len:number, <span class="Constant">1:literal</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> -<span class="CommentedCode">#? $print tem-len:number, [ ], $result-len:number, [ </span> -<span class="CommentedCode">#? ] #? 1</span> +<span class="CommentedCode">#? $print tem-len:number, [ ], $result-len:number, 10:literal/newline</span> rewind-ingredients _<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Comment"># skip template</span> <span class="Comment"># result = new array:character[result-len]</span> @@ -592,7 +571,7 @@ container buffer [ <span class="Comment"># result:boolean <- space? c:character</span> <span class="muRecipe">recipe</span> space? [ - <span class="Constant">new-default-space</span> + <span class="Constant">local-scope</span> c:character<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Comment"># most common case first</span> result:boolean<span class="Special"> <- </span>equal c:character, <span class="Constant">32:literal/space</span> @@ -657,7 +636,7 @@ container buffer [ <span class="Comment"># result:address:array:character <- trim s:address:array:character</span> <span class="muRecipe">recipe</span> trim [ - <span class="Constant">new-default-space</span> + <span class="Constant">local-scope</span> s:address:array:character<span class="Special"> <- </span><span class="Constant">next-ingredient</span> len:number<span class="Special"> <- </span>length s:address:array:character/deref <span class="Comment"># left trim: compute start</span> @@ -766,7 +745,7 @@ container buffer [ <span class="Comment"># next-index:number <- find-next text:address:array:character, pattern:character</span> <span class="muRecipe">recipe</span> find-next [ - <span class="Constant">new-default-space</span> + <span class="Constant">local-scope</span> text:address:array:character<span class="Special"> <- </span><span class="Constant">next-ingredient</span> pattern:character<span class="Special"> <- </span><span class="Constant">next-ingredient</span> idx:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span> @@ -866,7 +845,7 @@ container buffer [ <span class="Comment"># like find-next, but searches for multiple characters</span> <span class="Comment"># fairly dumb algorithm</span> <span class="muRecipe">recipe</span> find-substring [ - <span class="Constant">new-default-space</span> + <span class="Constant">local-scope</span> text:address:array:character<span class="Special"> <- </span><span class="Constant">next-ingredient</span> pattern:address:array:character<span class="Special"> <- </span><span class="Constant">next-ingredient</span> idx:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span> @@ -945,7 +924,7 @@ container buffer [ <span class="Comment"># result:boolean <- match-at text:address:array:character, pattern:address:array:character, idx:number</span> <span class="Comment"># checks if substring matches at index 'idx'</span> <span class="muRecipe">recipe</span> match-at [ - <span class="Constant">new-default-space</span> + <span class="Constant">local-scope</span> text:address:array:character<span class="Special"> <- </span><span class="Constant">next-ingredient</span> pattern:address:array:character<span class="Special"> <- </span><span class="Constant">next-ingredient</span> idx:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span> @@ -1076,7 +1055,7 @@ container buffer [ <span class="Comment"># result:address:array:address:array:character <- split s:address:array:character, delim:character</span> <span class="muRecipe">recipe</span> split [ - <span class="Constant">new-default-space</span> + <span class="Constant">local-scope</span> s:address:array:character<span class="Special"> <- </span><span class="Constant">next-ingredient</span> delim:character<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Comment"># empty string? return empty array</span> @@ -1206,7 +1185,7 @@ container buffer [ <span class="Comment"># x:address:array:character, y:address:array:character <- split-first text:address:array:character, delim:character</span> <span class="muRecipe">recipe</span> split-first [ - <span class="Constant">new-default-space</span> + <span class="Constant">local-scope</span> text:address:array:character<span class="Special"> <- </span><span class="Constant">next-ingredient</span> delim:character<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Comment"># empty string? return empty strings</span> @@ -1241,7 +1220,7 @@ container buffer [ <span class="Comment"># result:address:array:character <- string-copy buf:address:array:character, start:number, end:number</span> <span class="Comment"># todo: make this generic</span> <span class="muRecipe">recipe</span> string-copy [ - <span class="Constant">new-default-space</span> + <span class="Constant">local-scope</span> buf:address:array:character<span class="Special"> <- </span><span class="Constant">next-ingredient</span> start:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span> end:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span> @@ -1301,7 +1280,7 @@ container buffer [ ] <span class="muRecipe">recipe</span> min [ - <span class="Constant">new-default-space</span> + <span class="Constant">local-scope</span> x:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span> y:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Delimiter">{</span> @@ -1313,7 +1292,7 @@ container buffer [ ] <span class="muRecipe">recipe</span> max [ - <span class="Constant">new-default-space</span> + <span class="Constant">local-scope</span> x:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span> y:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Delimiter">{</span> |