[REBOL] Re: About Parsing
From: brett:codeconscious at: 17-Jul-2001 13:23
Hi Rondon,
Response below.
> The problem is that I need to check specific labels. The Brett solve the
> problem, but I'm converting some labels to other patterns of metadata, so
I
> need to read the correct labels. I mean: Title, Author, Id, Subject,
Source,
> Abstract, etc. The labels are variant. They are not static. They are not
in
> sequence.
> I'd like just to check if the file has a label type, so print it. that's
it.
I'm confused as to what you want. I'm also confused as to the pattern of the
data. Your example showed a file with bibliographic records - all related to
one book I guess. But I'll assume you have multiple books in the file.
Checking for specific labels: What is it the text that you need to check
for - the label name "Author"
or the label value "Kann, James"?
Here is some example code to consider.
file: {Id: 27698
Author: Kann, James
Title: Crossroads of Life
Abstract: This book talks about the hard ways of life.
Source: State Public Library
Holdings: AGE 12308082
Id: 12345
Author: Handley, Brett
Title: Uncertainty in my mind's I :)
Source: Brett's home collection
}
; ----- start of example
search-for-labels: func [
"Searches the data file for specific labels."
data-file
label-types [block!]
] [
parse/all data-file [
any [
copy label to ":" skip any " " copy data to "^/" skip
(if find label-types label [print [join label ":" data]])
]
end
]
]
search-for-labels file ["Title" "Author"]
Brett.