Mercurial > repos > rhope
comparison string.rhope @ 92:e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 02 Aug 2010 00:58:55 -0400 |
parents | c25d75c2440b |
children | e09c2d1d6d5b |
comparison
equal
deleted
inserted
replaced
91:bcdc326b3d6e | 92:e73a93fb5de1 |
---|---|
140 } | 140 } |
141 }{ | 141 }{ |
142 out <- 0i32 | 142 out <- 0i32 |
143 } | 143 } |
144 | 144 |
145 } | |
146 | |
147 Int32@String Slice[string:out] | |
148 { | |
149 out <- Int32[[string]Flatten] | |
150 } | |
151 | |
152 Int32@String Cat[string:out] | |
153 { | |
154 out <- Int32[[string]Flatten] | |
145 } | 155 } |
146 | 156 |
147 Flatten@String[string:out] | 157 Flatten@String[string:out] |
148 { | 158 { |
149 out <- string | 159 out <- string |
246 { | 256 { |
247 [left]Byte[index] | 257 [left]Byte[index] |
248 { | 258 { |
249 rbyte <- [right]Byte[index] {} | 259 rbyte <- [right]Byte[index] {} |
250 { | 260 { |
251 Print["Could not fetch byte from right string at offset:"] | 261 Print[["Could not fetch byte from right string at offset:"]Append[String[index]]] |
252 { Print[index] } | 262 { Print[["Right string has type ID: "]Append[ String[ID[Blueprint Of[right]]] ]] |
263 { Print[[right]Byte Length] | |
264 { Print[[right]Length] | |
265 { Print[["Left string has type ID: "]Append[ String[ID[Blueprint Of[left]]] ]] | |
266 { Print[[left]Byte Length] | |
267 { Print[[left]Length] }}}}}} | |
253 out <- No | 268 out <- No |
254 } | 269 } |
255 ,out <- If[[~]=[rbyte]] | 270 ,out <- If[[~]=[rbyte]] |
256 { | 271 { |
257 out <- _=String[left,right,[index]+[1]] | 272 out <- _=String[left,right,[index]+[1]] |
359 Slice@String Slice[string,slicepoint:left,right] | 374 Slice@String Slice[string,slicepoint:left,right] |
360 { | 375 { |
361 //TODO: Handle invalid slicepoints | 376 //TODO: Handle invalid slicepoints |
362 sliceoffset <- CPOff to BOff[[[string]Source >>]Buffer >>, 0i32, [string]Offset >>, slicepoint] | 377 sliceoffset <- CPOff to BOff[[[string]Source >>]Buffer >>, 0i32, [string]Offset >>, slicepoint] |
363 left <- String Slice[[string]Source >>, [string]Offset >>, slicepoint, [sliceoffset]-[[string]Offset >>]] | 378 left <- String Slice[[string]Source >>, [string]Offset >>, slicepoint, [sliceoffset]-[[string]Offset >>]] |
364 right <- String Slice[[string]Source >>, sliceoffset, [[string]Length >>]-[slicepoint], [[[string]Source >>]Byte Length]-[sliceoffset]] | 379 right <- String Slice[[string]Source >>, sliceoffset, [[string]Length >>]-[slicepoint], [[string]Byte Length]-[[sliceoffset]-[[string]Offset >>]]] |
365 } | 380 } |
366 | 381 |
367 Blueprint String Cat | 382 Blueprint String Cat |
368 { | 383 { |
369 Left | 384 Left |
582 String@String Slice[string:out] | 597 String@String Slice[string:out] |
583 { | 598 { |
584 out <- string | 599 out <- string |
585 } | 600 } |
586 | 601 |
602 Replace[string,toreplace,with:out] | |
603 { | |
604 ,delim,after <-[string]Partition[toreplace] | |
605 { | |
606 wt <- Blueprint Of[with] | |
607 If[ [[[wt]=[String()]] Or [[wt]=[String Slice()]]] Or [[wt]=[String Cat()]] ] | |
608 { | |
609 replacement <- with | |
610 }{ | |
611 replacement <- [with]Index[[toreplace]Find[=[delim,?]]] | |
612 } | |
613 out <- [[~]Append[replacement]]Append[Replace[after,toreplace,with]] | |
614 } {} {} { | |
615 out <- string | |
616 } | |
617 } | |
618 | |
619 _Join[list,delim,current,index:out] | |
620 { | |
621 [list]Next[index] | |
622 { | |
623 out <- _Join[list, delim, [[current]Append[delim]]Append[String[[list]Index[~]]], ~] | |
624 }{ | |
625 out <- current | |
626 } | |
627 } | |
628 | |
629 Join[list,delim:out] | |
630 { | |
631 [list]First | |
632 { | |
633 out <- _Join[list, delim, String[[list]Index[~]], ~] | |
634 }{ | |
635 out <- "" | |
636 } | |
637 } | |
638 | |
639 Starts With[thing,starts with:out] | |
640 { | |
641 out <- [[thing]Slice[[starts with]Length]] = [starts with] | |
642 } | |
643 | |
644 Ends With[thing,ends with:out] | |
645 { | |
646 ,compare <- [thing]Slice[ [[thing]Length] - [[ends with]Length] ] | |
647 out <- [compare] = [ends with] | |
648 } | |
649 |