1. Re: Win32Lib --Duh

Greg Harris wrote:

> Hi Bret!
>
> I just noticed the code I sent you was a little sloppy for my standards.. it
> worked but wasn't well optimized..
> Why use for loops when you can take advantage of Euphoria's sequence
> operations and bool ops.
>
> include wildcard.e
>
> --Range function originally by Hawke'
> --Modified by Greg Harris
> function range(object data, integer low, integer high)
>   return data * (data>=low) * (data<=high)
> end function
>
> function isAlpha(sequence data)
>  --checks a string to see if it contains only
>  --valid alpha characters
>  sequence up
>  up = upper(data)
>  if find(0,range(up,'A','Z')) then
>     return 0
>  end if
>  return 1
> end function
>
> function isNumeric(sequence data)
>  --checks a string to see if it contains only
>  --valid numeric characters
>  --Returns: 1 if all numeric
>  --         0 if not.
>   if find(0,range(data,'0','9')) then
>      return 0
>   end if
>   return 1
> end function
>
> ---------------------------- end code-------------------------------
>
> Hope this helps,
> Greg Harris

Wohoho, from that, you can reduce the number of statements with the following
code:

-- Code starts here --
include wildcard.e

--Range function originally by Hawke'
--Modified by Greg Harris
function range(object data, integer low, integer high)
  return data * (data>=low) * (data<=high)
end function

-- isAlpha(), modified by The AfterBeat --
function isAlpha(sequence data)
 --checks a string to see if it contains only
 --valid alpha characters
 return find(0, range(upper(data), 'A', 'Z')) == 0
end function

-- isNumeric(), modified by The AfterBeat --
function isNumeric(sequence data)
 --checks a string to see if it contains only
 --valid numeric characters
 --Returns: 1 if all numeric
 --         0 if not.
 return find(0, range(data, '0', '9')) == 0
end function

-- Code ends here --

Sorry for the "I'm better than everyone" intro, I just thought it sounded cool.
I am aware that I'm not the best programmer in the world.  I just wanted to
throw my two cents in.  Heh.

   The AfterBeat (afterbeat at geocities.com or afterbeat at hotmail.com)

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu