about summary refs log tree commit diff stats
path: root/html/092socket.mu.html
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-10-23 17:58:37 -0700
committerKartik K. Agaram <vc@akkartik.com>2016-10-23 17:58:37 -0700
commit09788d7edfd63e89b05413c0279fa112e237ee50 (patch)
treee9b063b292a8bcd9264ce7c75d1d4e1454949579 /html/092socket.mu.html
parenta9817844aea80b5d07baecb55e214775cf0f6c9e (diff)
downloadmu-09788d7edfd63e89b05413c0279fa112e237ee50.tar.gz
3567
Diffstat (limited to 'html/092socket.mu.html')
-rw-r--r--html/092socket.mu.html35
1 files changed, 34 insertions, 1 deletions
diff --git a/html/092socket.mu.html b/html/092socket.mu.html
index 186c7c3b..b8c44663 100644
--- a/html/092socket.mu.html
+++ b/html/092socket.mu.html
@@ -92,12 +92,13 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color
   ]
 ]
 
-<span class="muRecipe">def</span> start-reading-from-network resources:&amp;:resources, host:text, path:text<span class="muRecipe"> -&gt; </span>contents:&amp;:source:char [
+<span class="muRecipe">def</span> start-reading-from-network resources:&amp;:resources, uri:text<span class="muRecipe"> -&gt; </span>contents:&amp;:source:char [
   <span class="Constant">local-scope</span>
   <span class="Constant">load-ingredients</span>
   <span class="Delimiter">{</span>
     <span class="muControl">break-if</span> resources
     <span class="Comment"># real network</span>
+    host:text, path:text<span class="Special"> &lt;- </span>split-at uri, <span class="Constant">47/slash</span>
     socket:num<span class="Special"> &lt;- </span>$open-client-socket host, <span class="Constant">80/http-port</span>
     assert socket, <span class="Constant">[contents]</span>
     req:text<span class="Special"> &lt;- </span>interpolate <span class="Constant">[GET _ HTTP/1.1]</span>, path
@@ -230,6 +231,38 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color
     <span class="muControl">loop</span>
   <span class="Delimiter">}</span>
 ]
+
+<span class="Comment"># like split-first, but don't eat the delimiter</span>
+<span class="muRecipe">def</span> split-at text:text, delim:char<span class="muRecipe"> -&gt; </span>x:text, y:text [
+  <span class="Constant">local-scope</span>
+  <span class="Constant">load-ingredients</span>
+  <span class="Comment"># empty text? return empty texts</span>
+  len:num<span class="Special"> &lt;- </span>length *text
+  <span class="Delimiter">{</span>
+    empty?:bool<span class="Special"> &lt;- </span>equal len, <span class="Constant">0</span>
+    <span class="muControl">break-unless</span> empty?
+    x:text<span class="Special"> &lt;- </span>new <span class="Constant">[]</span>
+    y:text<span class="Special"> &lt;- </span>new <span class="Constant">[]</span>
+    <span class="muControl">return</span>
+  <span class="Delimiter">}</span>
+  idx:num<span class="Special"> &lt;- </span>find-next text, delim, <span class="Constant">0</span>
+  x:text<span class="Special"> &lt;- </span>copy-range text, <span class="Constant">0</span>, idx
+  y:text<span class="Special"> &lt;- </span>copy-range text, idx, len
+]
+
+<span class="muScenario">scenario</span> text-split-at [
+  <span class="Constant">local-scope</span>
+  x:text<span class="Special"> &lt;- </span>new <span class="Constant">[a/b]</span>
+  run [
+    y:text, z:text<span class="Special"> &lt;- </span>split-at x, <span class="Constant">47/slash</span>
+    <span class="Constant">10</span>:@:char/<span class="Special">raw &lt;- </span>copy *y
+    <span class="Constant">20</span>:@:char/<span class="Special">raw &lt;- </span>copy *z
+  ]
+  memory-should-contain [
+    <span class="Constant">10</span>:array:character<span class="Special"> &lt;- </span><span class="Constant">[a]</span>
+    <span class="Constant">20</span>:array:character<span class="Special"> &lt;- </span><span class="Constant">[/b]</span>
+  ]
+]
 </pre>
 </body>
 </html>