Mercurial > repos > tabletprog
comparison 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 |
comparison
equal
deleted
inserted
replaced
150:7dfa4481deb0 | 151:3e9cb69e516d |
---|---|
119 intret num!: i | 119 intret num!: i |
120 intret | 120 intret |
121 } | 121 } |
122 } | 122 } |
123 | 123 |
124 llMessage: from:withLength withVars: { | |
125 from <- obj_int32 ptr | |
126 tocopy <- obj_int32 ptr | |
127 ret <- string ptr | |
128 start <- int32_t | |
129 clampedLen <- int32_t | |
130 } andCode: :from :tocopy { | |
131 start <- from num | |
132 if: start < 0 { | |
133 start <- bytes + start | |
134 } | |
135 if: start > bytes { | |
136 start <- bytes | |
137 } | |
138 clampedLen <- tocopy num | |
139 if: start + clampedLen > bytes { | |
140 clampedLen <- bytes - start | |
141 } | |
142 ret <- make_object: (addr_of: string_meta) NULL 0 | |
143 ret data!: (GC_MALLOC_ATOMIC: clampedLen + 1) | |
144 memcpy: (ret data) data + start clampedLen | |
145 ret len!: clampedLen | |
146 ret bytes!: clampedLen | |
147 ret | |
148 } | |
149 | |
150 from <- :start { | |
151 from: start withLength: length | |
152 } | |
153 | |
124 isInteger? <- { false } | 154 isInteger? <- { false } |
125 } | 155 } |