Mercurial > repos > rhope
diff string.rhope @ 71:c40c3d399133
Add Int32@String and Get Char. Fix stack bug
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Fri, 18 Jun 2010 15:07:09 -0400 |
parents | d0ce696786cc |
children | f7bcf3db1342 |
line wrap: on
line diff
--- a/string.rhope Wed Jun 16 04:36:53 2010 +0000 +++ b/string.rhope Fri Jun 18 15:07:09 2010 -0400 @@ -96,6 +96,51 @@ { out <- write[1i32, [Array[]]Append[10u8], 1i64] } } +Get Char[:out] +{ + read[0, [Array[]]Set[0, 0u8], 1i64] + {} + { out <- String[~] } +} + +_String to Int32[current,index,array:out] +{ + char <- [array]Index[index] + { + If[[char]<[48u8]] + { + out <- Val[current] + }{ + If[[char]>[57u8]] + { + out <- Val[current] + }{ + out <- _String to Int32[[[current]*[10i32]]+[Int32[[char]-[48u8]]], [index]+[1], array] + } + } + + }{ + out <- Val[current] + } +} + +Int32@String[string:out] +{ + buf <- [string]Buffer >> + [buf]Index[0] + { + If[[~]=[45u8]] + { + out <- [0i32]-[_String to Int32[0i32, 1, buf]] + }{ + out <- _String to Int32[0i32, 0, buf] + } + }{ + out <- 0i32 + } + +} + Flatten@String[string:out] { out <- string