Mercurial > repos > rhope
diff 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 |
line wrap: on
line diff
--- a/string.rhope Sat Jul 31 17:17:23 2010 -0400 +++ b/string.rhope Mon Aug 02 00:58:55 2010 -0400 @@ -144,6 +144,16 @@ } +Int32@String Slice[string:out] +{ + out <- Int32[[string]Flatten] +} + +Int32@String Cat[string:out] +{ + out <- Int32[[string]Flatten] +} + Flatten@String[string:out] { out <- string @@ -248,8 +258,13 @@ { rbyte <- [right]Byte[index] {} { - Print["Could not fetch byte from right string at offset:"] - { Print[index] } + Print[["Could not fetch byte from right string at offset:"]Append[String[index]]] + { Print[["Right string has type ID: "]Append[ String[ID[Blueprint Of[right]]] ]] + { Print[[right]Byte Length] + { Print[[right]Length] + { Print[["Left string has type ID: "]Append[ String[ID[Blueprint Of[left]]] ]] + { Print[[left]Byte Length] + { Print[[left]Length] }}}}}} out <- No } ,out <- If[[~]=[rbyte]] @@ -361,7 +376,7 @@ //TODO: Handle invalid slicepoints sliceoffset <- CPOff to BOff[[[string]Source >>]Buffer >>, 0i32, [string]Offset >>, slicepoint] left <- String Slice[[string]Source >>, [string]Offset >>, slicepoint, [sliceoffset]-[[string]Offset >>]] - right <- String Slice[[string]Source >>, sliceoffset, [[string]Length >>]-[slicepoint], [[[string]Source >>]Byte Length]-[sliceoffset]] + right <- String Slice[[string]Source >>, sliceoffset, [[string]Length >>]-[slicepoint], [[string]Byte Length]-[[sliceoffset]-[[string]Offset >>]]] } Blueprint String Cat @@ -584,3 +599,51 @@ out <- string } +Replace[string,toreplace,with:out] +{ + ,delim,after <-[string]Partition[toreplace] + { + wt <- Blueprint Of[with] + If[ [[[wt]=[String()]] Or [[wt]=[String Slice()]]] Or [[wt]=[String Cat()]] ] + { + replacement <- with + }{ + replacement <- [with]Index[[toreplace]Find[=[delim,?]]] + } + out <- [[~]Append[replacement]]Append[Replace[after,toreplace,with]] + } {} {} { + out <- string + } +} + +_Join[list,delim,current,index:out] +{ + [list]Next[index] + { + out <- _Join[list, delim, [[current]Append[delim]]Append[String[[list]Index[~]]], ~] + }{ + out <- current + } +} + +Join[list,delim:out] +{ + [list]First + { + out <- _Join[list, delim, String[[list]Index[~]], ~] + }{ + out <- "" + } +} + +Starts With[thing,starts with:out] +{ + out <- [[thing]Slice[[starts with]Length]] = [starts with] +} + +Ends With[thing,ends with:out] +{ + ,compare <- [thing]Slice[ [[thing]Length] - [[ends with]Length] ] + out <- [compare] = [ends with] +} +