Re: Help reading and displaying
- Posted by George Henry <ghenryca at HOTMAIL.COM> Dec 08, 2000
- 459 views
Hi gals and guys, (What could be more politically correct?) (Perhaps masochistically) for parsing I like a couple of functions I cooked up a long time ago, based on some C standard library routines. My original C functoins were called strskip and strskipn. Here are Euphoria versions, plus some useful related routines: -- skip -- global function skip -- -- Returns the index of the first element of in_this that is NOT -- also found in skip_this, or length(skip_this) + 1 if no such -- element exists. I.e. skips over the leading elements of in_this -- that are in both sequences. -- This is particularly useful in parsing text. global function skip(sequence skip_this, sequence in_this) integer index index = 1 while index <= length(in_this) and find(in_this[index], skip_this) > 0 do index += 1 end while return index end function -- skipr -- global function skipr -- -- Returns the index of the last element of in_this that is NOT -- also found in skip_this, or 0 if no such element exists. I.e. -- skips backward over the trailing elements of in_this that are in -- both sequences. This may be useful in parsing text. global function skipr(sequence skip_this, sequence in_this) integer index index = length(in_this) while index >= 1 and find(in_this[index], skip_this) > 0 do index -= 1 end while return index end function -- skipn -- global function skipn -- -- Returns the index of the first element of in_this that is also -- found in skip_this, or length(skip_this) + 1 if no such element -- exists. I.e. skips over the leading elements of in_this that are -- NOT in both sequences. -- This is particularly useful in parsing text. global function skipn(sequence skip_non_this, sequence in_this) integer index index = 1 while index <= length(in_this) and find(in_this[index], skip_non_this) = 0 do index += 1 end while return index end function -- skipnr -- global function skipnr -- -- Returns the index of the last element of in_this that is also -- found in skip_this, or 0 if no such element exists. I.e. skips -- backward over the trailing elements of in_this that are NOT in -- both sequences. -- This may be useful in parsing text. global function skipnr(sequence skip_non_this, sequence in_this) integer index index = length(in_this) while index >= 1 and find(in_this[index], skip_non_this) = 0 do index -= 1 end while return index end function -- DEFAULT_WHITESPACE -- global constant DEFAULT_WHITESPACE -- -- Defines whitespace as space, tab, or newline. -- Other useful definitions are possible. global constant DEFAULT_WHITESPACE = " \t\n" -- ltrim -- global function ltrim -- -- Returns a string trimmed of leading "whitespace". global function ltrim(vector string, vector whitespace) return string[skip(whitespace, string)..length(string)] end function -- rtrim -- global function rtrim -- -- Returns a string trimmed of trailing "whitespace". global function rtrim(vector string, vector whitespace) return string[1..skipr(whitespace, string)] end function Offered with the usual disclaimers, George _____________________________________________________________________________________ Get more from the Web. FREE MSN Explorer download : http://explorer.msn.com