comparison modules/string.tp @ 311:dfd204c82849

Merge
author Michael Pavone <pavone@retrodev.com>
date Fri, 01 Aug 2014 18:56:50 -0700
parents 8dbb2d2522a5
children 74cab9b5f2a4
comparison
equal deleted inserted replaced
310:2308336790d4 311:dfd204c82849
209 } 209 }
210 if: start > bytes { 210 if: start > bytes {
211 start <- bytes 211 start <- bytes
212 } 212 }
213 clampedLen <- tocopy num 213 clampedLen <- tocopy num
214 if: clampedLen < 0 {
215 clampedLen <- bytes - clampedLen
216 if: clampedLen < 0 {
217 clampedLen <- 0
218 }
219 }
214 if: start + clampedLen > bytes { 220 if: start + clampedLen > bytes {
215 clampedLen <- bytes - start 221 clampedLen <- bytes - start
216 } 222 }
217 ret <- make_object: (addr_of: string_meta) NULL 0 223 ret <- make_object: (addr_of: string_meta) NULL 0
218 ret data!: (GC_MALLOC_ATOMIC: clampedLen + 1) 224 ret data!: (GC_MALLOC_ATOMIC: clampedLen + 1)
219 memcpy: (ret data) data + start clampedLen 225 memcpy: (ret data) data + start clampedLen
220 ret len!: clampedLen 226 ret len!: clampedLen
221 ret bytes!: clampedLen 227 ret bytes!: clampedLen
228 (ret data) set: clampedLen 0
222 ret 229 ret
223 } 230 }
224 231
225 from <- :start { 232 from <- :start {
226 from: start withLength: length 233 from: start withLength: length
290 b = space || b = tab || b = nl || b = cr 297 b = space || b = tab || b = nl || b = cr
291 } 298 }
292 } do: { 299 } do: {
293 start <- start + 1 300 start <- start + 1
294 } 301 }
295 end <- l 302 end <- l - 1
296 while: { 303 while: {
297 if: end > 0 { 304 if: end > start {
298 b <- byte: end - 1 305 b <- byte: end
299 b = space || b = tab || b = nl || b = cr 306 b = space || b = tab || b = nl || b = cr
300 } 307 }
301 } do: { 308 } do: {
302 end <- end - 1 309 end <- end - 1
303 } 310 }
304 from: start withLength: (end - start) 311 from: start withLength: (end + 1 - start)
312 }
313
314 startsWith? <- :prefix {
315 if: (prefix length) <= length {
316 0 = (compareSub: prefix 0 0 (prefix length))
317 }
305 } 318 }
306 319
307 endsWith? <- :suffix { 320 endsWith? <- :suffix {
308 if: (suffix length) <= length { 321 if: (suffix length) <= length {
309 0 = (compareSub: suffix (length - (suffix length)) 0 (suffix length)) 322 0 = (compareSub: suffix (length - (suffix length)) 0 (suffix length))