diff options
author | Ori Bernstein <ori@eigenstate.org> | 2015-08-26 12:20:58 -0700 |
---|---|---|
committer | Ori Bernstein <ori@eigenstate.org> | 2015-08-26 12:20:58 -0700 |
commit | 2bc852bda98762d3bc01548bf972e3f1b137fbfb (patch) | |
tree | 74831deed3c9057c5fe0cbb8790d220e855bc792 /lib/std/cstrconv.myr | |
parent | 3de952510eb2a23350d24ed926f19c0cf72a12f2 (diff) | |
download | mc-2bc852bda98762d3bc01548bf972e3f1b137fbfb.tar.gz |
Move Myrddin libs to lib/ subdirectory.
Diffstat (limited to 'lib/std/cstrconv.myr')
-rw-r--r-- | lib/std/cstrconv.myr | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/std/cstrconv.myr b/lib/std/cstrconv.myr new file mode 100644 index 0000000..fa9e0bf --- /dev/null +++ b/lib/std/cstrconv.myr @@ -0,0 +1,40 @@ +use "types.use" + +pkg std = + const cstrlen : (buf : byte[:] -> size) + const cstrconv : (buf : byte[:] -> byte[:]) + const cstrconvp : (p : byte# -> byte[:]) +;; + +const cstrconv = {buf + var i + + for i = 0; i < buf.len; i++ + if buf[i] == 0 + -> buf[:i] + ;; + ;; + -> buf +} + +const cstrconvp = {p + var i, base + + i = 0 + base = p castto(intptr) + while ((base + i) castto(byte#))# != 0 + i++ + ;; + -> p[:i] +} + +const cstrlen = {buf + var i + + for i = 0; i < buf.len; i++ + if buf[i] == 0 + break + ;; + ;; + -> i +} |