[REBOL] Re: Core 2.6 - Last minute requests - take your chance!
From: tbrownell:shaw:ca at: 7-Apr-2002 0:48
Another request, as mentioned in earlier posts (shutting off the parse
features) a parse/white switch that turns off the automated comma, quote and
semicolon parsing rules eg;
parse/white none {Hello world, "this too" is an example;} ;will return...
==["Hello" "world," "this" "to" "is" "an" "example;"]
currently it returns...
["Hello" "world" "this too" "is" "an" "example"]
I've included Joel's response below.
Terry Brownell
>Hi, Carl, Terry, and all
>A slightly more generic version...
>Carl Read wrote:
>
> On 09-Mar-02, Terry Brownell wrote:
>
> > When parsing a string such as {Hello world, "this to" is an
> > example;} parse will remove the comma, and the semi... and takes
> > anything within quotes as a single value.
>
> > Sometimes I just want to parse spaces so we get...
> > ["Hello" "world," "this" "to" "is" "an" "example;"]
>
...
> Well, the 'all refinement let's you parse everything except what you
> tell it not to parse. ie...
>
...
> Though your "this to" becomes one string instead of two. Close to
> what you want though, and stripping out the speach-marks first would
> be one option. ie...
>
just-the-good-parts: func [
s [string!]
/local result good-ones others fragment
][
good-ones: charset [#"A" - #"Z" #"a" - #"z" #"." #"," #";"]
others: complement good-ones
result: copy []
parse/all s [
any [
copy fragment some good-ones (append result fragment)
|
some others
]
]
result
]
>> a: {Hello world, "this to" is an example;}
== {Hello world, "this to" is an example;}
>> just-the-good-parts a
== ["Hello" "world," "this" "to" "is" "an" "example;"]
Suitable redefinitions of GOOD-ONES and OTHERS will let you keep or
discard whatever characters you wish, of course.
-jn-