about summary refs log tree commit diff stats
path: root/html/060string.mu.html
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-06-09 00:02:23 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-06-09 00:02:23 -0700
commite8b1d3ff06bdfcc0005c70ccd99cd26cba3e1eef (patch)
treeefd145601d5249dfde18b5be7be3b95e229717d7 /html/060string.mu.html
parentfd1e8afdc9f68612f207d75b31b2011e8e738a47 (diff)
downloadmu-e8b1d3ff06bdfcc0005c70ccd99cd26cba3e1eef.tar.gz
1549
Diffstat (limited to 'html/060string.mu.html')
-rw-r--r--html/060string.mu.html42
1 files changed, 34 insertions, 8 deletions
diff --git a/html/060string.mu.html b/html/060string.mu.html
index ee17699c..18869d3c 100644
--- a/html/060string.mu.html
+++ b/html/060string.mu.html
@@ -10,8 +10,8 @@
 <meta name="colorscheme" content="minimal">
 <style type="text/css">
 <!--
-pre { white-space: pre-wrap; font-family: monospace; color: #d0d0d0; background-color: #080808; }
-body { font-family: monospace; color: #d0d0d0; background-color: #080808; }
+pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; }
+body { font-family: monospace; color: #eeeeee; background-color: #080808; }
 * { font-size: 1em; }
 .CommentedCode { color: #6c6c6c; }
 .Delimiter { color: #c000c0; }
@@ -190,13 +190,22 @@ container buffer [
   <span class="Identifier">default-space</span>:address:array:location<span class="Special"> &lt;- </span>new location:type, <span class="Constant">30:literal</span>
   in:address:buffer<span class="Special"> &lt;- </span><span class="Identifier">next-ingredient</span>
   c:character<span class="Special"> &lt;- </span><span class="Identifier">next-ingredient</span>
+  len:address:number<span class="Special"> &lt;- </span>get-address in:address:buffer/deref, length:offset
+  <span class="Delimiter">{</span>
+    <span class="Comment"># backspace? just drop last character if it exists and return</span>
+    backspace?:boolean<span class="Special"> &lt;- </span>equal c:character, <span class="Constant">8:literal/backspace</span>
+    <span class="Identifier">break-unless</span> backspace?:boolean
+    empty?:boolean<span class="Special"> &lt;- </span>lesser-or-equal len:address:number/deref, <span class="Constant">0:literal</span>
+    <span class="Identifier">reply-if</span> empty?:boolean, in:address:buffer/same-as-ingredient:0
+    len:address:number/deref<span class="Special"> &lt;- </span>subtract len:address:number/deref, <span class="Constant">1:literal</span>
+    <span class="Identifier">reply</span> in:address:buffer/same-as-ingredient:0
+  <span class="Delimiter">}</span>
   <span class="Delimiter">{</span>
     <span class="Comment"># grow buffer if necessary</span>
     full?:boolean<span class="Special"> &lt;- </span>buffer-full? in:address:buffer
     <span class="Identifier">break-unless</span> full?:boolean
     in:address:buffer<span class="Special"> &lt;- </span>grow-buffer in:address:buffer
   <span class="Delimiter">}</span>
-  len:address:number<span class="Special"> &lt;- </span>get-address in:address:buffer/deref, length:offset
   s:address:array:character<span class="Special"> &lt;- </span>get in:address:buffer/deref, data:offset
   dest:address:character<span class="Special"> &lt;- </span>index-address s:address:array:character/deref, len:address:number/deref
   dest:address:character/deref<span class="Special"> &lt;- </span>copy c:character
@@ -256,6 +265,23 @@ container buffer [
   ]
 ]
 
+<span class="muScenario">scenario</span> buffer-append-handles-backspace [
+  run [
+    <span class="Identifier">default-space</span>:address:array:location<span class="Special"> &lt;- </span>new location:type, <span class="Constant">30:literal</span>
+    x:address:buffer<span class="Special"> &lt;- </span>init-buffer <span class="Constant">3:literal</span>
+    x:address:buffer<span class="Special"> &lt;- </span>buffer-append x:address:buffer, <span class="Constant">97:literal</span>  <span class="Comment"># 'a'</span>
+    x:address:buffer<span class="Special"> &lt;- </span>buffer-append x:address:buffer, <span class="Constant">98:literal</span>  <span class="Comment"># 'b'</span>
+    x:address:buffer<span class="Special"> &lt;- </span>buffer-append x:address:buffer, <span class="Constant">8:literal/backspace</span>
+    s:address:array:character<span class="Special"> &lt;- </span>buffer-to-array x:address:buffer
+    1:array:character/<span class="Special">raw &lt;- </span>copy s:address:array:character/deref
+  ]
+  memory-should-contain [
+    1<span class="Special"> &lt;- </span>1   <span class="Comment"># length</span>
+    2<span class="Special"> &lt;- </span>97  <span class="Comment"># contents</span>
+    3<span class="Special"> &lt;- </span>0
+  ]
+]
+
 <span class="Comment"># result:address:array:character &lt;- integer-to-decimal-string n:number</span>
 <span class="muRecipe">recipe</span> integer-to-decimal-string [
   <span class="Identifier">default-space</span>:address:array:location<span class="Special"> &lt;- </span>new location:type, <span class="Constant">30:literal</span>
@@ -316,15 +342,15 @@ container buffer [
 <span class="muRecipe">recipe</span> buffer-to-array [
   <span class="Identifier">default-space</span>:address:array:character<span class="Special"> &lt;- </span>new location:type, <span class="Constant">30:literal</span>
   in:address:buffer<span class="Special"> &lt;- </span><span class="Identifier">next-ingredient</span>
-  len:number<span class="Special"> &lt;- </span>get in:address:buffer/deref, length:offset
-<span class="CommentedCode">#?   $print [size ], len:number, [ </span>
-<span class="CommentedCode">#? ] #? 1</span>
-  s:address:array:character<span class="Special"> &lt;- </span>get in:address:buffer/deref, data:offset
   <span class="Delimiter">{</span>
     <span class="Comment"># propagate null buffer</span>
-    <span class="Identifier">break-if</span> s:address:array:character
+    <span class="Identifier">break-if</span> in:address:buffer
     <span class="Identifier">reply</span> <span class="Constant">0:literal</span>
   <span class="Delimiter">}</span>
+  len:number<span class="Special"> &lt;- </span>get in:address:buffer/deref, length:offset
+<span class="CommentedCode">#?   $print [size ], len:number, [ </span>
+<span class="CommentedCode">#? ] #? 1</span>
+  s:address:array:character<span class="Special"> &lt;- </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"> &lt;- </span>new character:type, len:number
   i:number<span class="Special"> &lt;- </span>copy <span class="Constant">0:literal</span>