1. Type String
- Posted by lgregg at BIG12.METROBBS.COM Mar 10, 1999
- 332 views
- Last edited Mar 11, 1999
Gabriel Boehme suggested a solution for the string type function. I suggest some small changes below, with x's beneath the changes. This way, if s is not a sequence, Euphoria will not abort. Larry Gregg ------------------------------------------------------------------------ global type string(object s) --xxxxxx xxxxxx object c -- thanks Rod Jackson! if not sequence (s) then return 0 end if -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx for i = 1 to length(s) do c = s[i] if not integer(c) then -- strings cannot contain sequences or floating-point values return 0 elsif c < 0 or c > 255 then -- not a byte value return 0 end if end for -- if we've made it here, it's a string return 1 end type ------------------------------------------------------------------------- --It took me quite a few false starts for me to get this completed. As you can --see, we have to look for *much* more than just the range of the values. We --have to check each element to be sure it's an integer value (and not a --floating-point value or even another sequence), *before* we can verify the --range of values. To my knowledge, there isn't any more "elegant" way of --doing this, though I'd be quite happy to be proven wrong. --Gabriel Boehme