diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2016-10-23 17:58:37 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2016-10-23 17:58:37 -0700 |
commit | 09788d7edfd63e89b05413c0279fa112e237ee50 (patch) | |
tree | e9b063b292a8bcd9264ce7c75d1d4e1454949579 /html/092socket.mu.html | |
parent | a9817844aea80b5d07baecb55e214775cf0f6c9e (diff) | |
download | mu-09788d7edfd63e89b05413c0279fa112e237ee50.tar.gz |
3567
Diffstat (limited to 'html/092socket.mu.html')
-rw-r--r-- | html/092socket.mu.html | 35 |
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:&:resources, host:text, path:text<span class="muRecipe"> -> </span>contents:&:source:char [ +<span class="muRecipe">def</span> start-reading-from-network resources:&:resources, uri:text<span class="muRecipe"> -> </span>contents:&: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"> <- </span>split-at uri, <span class="Constant">47/slash</span> socket:num<span class="Special"> <- </span>$open-client-socket host, <span class="Constant">80/http-port</span> assert socket, <span class="Constant">[contents]</span> req:text<span class="Special"> <- </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"> -> </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"> <- </span>length *text + <span class="Delimiter">{</span> + empty?:bool<span class="Special"> <- </span>equal len, <span class="Constant">0</span> + <span class="muControl">break-unless</span> empty? + x:text<span class="Special"> <- </span>new <span class="Constant">[]</span> + y:text<span class="Special"> <- </span>new <span class="Constant">[]</span> + <span class="muControl">return</span> + <span class="Delimiter">}</span> + idx:num<span class="Special"> <- </span>find-next text, delim, <span class="Constant">0</span> + x:text<span class="Special"> <- </span>copy-range text, <span class="Constant">0</span>, idx + y:text<span class="Special"> <- </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"> <- </span>new <span class="Constant">[a/b]</span> + run [ + y:text, z:text<span class="Special"> <- </span>split-at x, <span class="Constant">47/slash</span> + <span class="Constant">10</span>:@:char/<span class="Special">raw <- </span>copy *y + <span class="Constant">20</span>:@:char/<span class="Special">raw <- </span>copy *z + ] + memory-should-contain [ + <span class="Constant">10</span>:array:character<span class="Special"> <- </span><span class="Constant">[a]</span> + <span class="Constant">20</span>:array:character<span class="Special"> <- </span><span class="Constant">[/b]</span> + ] +] </pre> </body> </html> |