1. Type String

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

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu