Mercurial > repos > tabletprog
diff modules/string.tp @ 151:3e9cb69e516d
Added from and from:withLength for doing substring operations
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Fri, 09 Aug 2013 13:20:40 -0700 |
parents | 7dfa4481deb0 |
children | a6739206a9e3 |
line wrap: on
line diff
--- a/modules/string.tp Fri Aug 09 10:05:20 2013 -0700 +++ b/modules/string.tp Fri Aug 09 13:20:40 2013 -0700 @@ -121,5 +121,35 @@ } } + llMessage: from:withLength withVars: { + from <- obj_int32 ptr + tocopy <- obj_int32 ptr + ret <- string ptr + start <- int32_t + clampedLen <- int32_t + } andCode: :from :tocopy { + start <- from num + if: start < 0 { + start <- bytes + start + } + if: start > bytes { + start <- bytes + } + clampedLen <- tocopy num + if: start + clampedLen > bytes { + clampedLen <- bytes - start + } + ret <- make_object: (addr_of: string_meta) NULL 0 + ret data!: (GC_MALLOC_ATOMIC: clampedLen + 1) + memcpy: (ret data) data + start clampedLen + ret len!: clampedLen + ret bytes!: clampedLen + ret + } + + from <- :start { + from: start withLength: length + } + isInteger? <- { false } }