Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Quote character replacement

 [1/10] from: rgaither:triad:rr at: 26-Feb-2001 11:18


Hi All, A quick challenge to the list! :-) In starting to play with parse I have a very structured file to process. It is almost perfect for the newer block parsing options - except - It has some quoted strings - Description "This is a sample field description" where the string wraps around a line. It seems if I could change the " " into { } respectively then I could use the block parsing features. There must be a dozen ways to do this, any takers? Thanks, Rod. Rod Gaither Oak Ridge, NC - USA [rgaither--triad--rr--com]

 [2/10] from: rgaither:triad:rr at: 26-Feb-2001 12:37


Hi All,
> It seems if I could change the " " into { } respectively > then I could use the block parsing features.
Here is my first run at a function to change quotes to braces to manage long strings properly. REBOL [ Title: "Change quotes to braces" Author: "Rod Gaither" File: %fixquotes.r Date: 26-Feb-2001 Purpose: {Test utility function to prepare .df file.} Category: [script util text 2] ] fix-quotes: func [in-string [string!] /local new-string in-quote?] [ new-string: make string! length? in-string in-quote?: false foreach char in-string [ either char = #"^(22)" [ either in-quote? [ append new-string #"^}" ][ append new-string #"^{" ] in-quote?: not in-quote? ][ append new-string char ] ] return new-string ] Rather plain and inefficient, waiting for much better option! :-) FWIW, Rod. Rod Gaither Oak Ridge, NC - USA [rgaither--triad--rr--com]

 [3/10] from: gjones05:mail:orion at: 26-Feb-2001 12:09


From: Rod Gaither
> In starting to play with parse I have a very structured > file to process. It is almost perfect for the newer block
<<quoted lines omitted: 7>>
> There must be a dozen ways to do this, any takers? <snip>
Hi, Rod, I will apologize in advance in case I have mis-understood the requirements, but perhaps simply using 'parse will work. Using your example for an example: a: { Description "This is a sample field description" } parse a none ; yields ["Description" "This is a sample field^/description"] Or are you looking for a finer degree of parsing? --Scott Jones

 [4/10] from: rgaither:triad:rr at: 26-Feb-2001 13:41


Hi Scott,
>a: { > Description "This is a sample field >description" >} > >parse a none ; yields ["Description" "This is a sample >field^/description"]
Not what I was looking for but very enlightening, and a completely different way to solve the problem. I included the general problem for just such a result, though I would still like to see a short and sweet quote conversion function. Thanks, Rod. Rod Gaither Oak Ridge, NC - USA [rgaither--triad--rr--com]

 [5/10] from: rebol:techscribe at: 26-Feb-2001 10:54


Hi Rod, Do you need to preserve the newlines in the string? Elan

 [6/10] from: rgaither:triad:rr at: 26-Feb-2001 14:13


Hi Elan,
>Do you need to preserve the newlines in the string?
No, they were introduced into the file due to some output wrapping. Thanks, Rod. p.s. Your book has been a great help these last couple of days! Rod Gaither Oak Ridge, NC - USA [rgaither--triad--rr--com]

 [7/10] from: g::santilli::tiscalinet::it at: 26-Feb-2001 21:17


Hello Rod! On 26-Feb-01, you wrote: RG> Hi Elan, RG>> Do you need to preserve the newlines in the string? RG> No, they were introduced into the file due to some output RG> wrapping. Then I can imagine what Elan's going to propose: replace all newlines with a space. Anyway, just for fun, let's try converting those quotes.
>> rule: [any [to {"} mark: skip (change mark "{") to {"} mark: skip (change mark "}")]]
== [any [to {"} mark: skip (change mark "{") to {"} mark: skip (change mark "}")]]
>> test: {
{ Description "This is a sample field { description" { } == { Description "This is a sample field description" }
>> parse/all test rule
== false
>> test
== { Description {This is a sample field description} }
>> test: {
{ it "should" be able to "convert your { quotes" as long as they are balanced. { "Hope this helps." { } == { it "should" be able to "convert your quotes" as long as they are balanced. Hope this helps. }
>> parse/all test rule
== false
>> test
== { it {should} be able to {convert your quotes} as long as they are balanced. {Hope this helps.} } Regards, Gabriele. -- Gabriele Santilli <[giesse--writeme--com]> - Amigan - REBOL programmer Amiga Group Italia sez. L'Aquila -- http://www.amyresource.it/AGI/

 [8/10] from: rgaither:triad:rr at: 26-Feb-2001 15:42


Hi Gabriele,
>Then I can imagine what Elan's going to propose: replace all >newlines with a space.
Another novel approach to the real problem, not just what I asked for. :-)
>Anyway, just for fun, let's try converting those quotes. > >>> rule: [any [to {"} mark: skip (change mark "{") to {"} mark: skip (change mark "}")]] >== [any [to {"} mark: skip (change mark "{") to {"} mark: skip (change mark "}")]]
Excellent! Both a solution and a lesson in parse at the same time. :-)
>it {should} be able to {convert your >quotes} as long as they are balanced. >{Hope this helps.} >}
They are, thanks a bunch. Rod. Rod Gaither Oak Ridge, NC - USA [rgaither--triad--rr--com]

 [9/10] from: rebol:techscribe at: 26-Feb-2001 14:04


Hi Gabriele, you wrote:
> Then I can imagine what Elan's going to propose: replace all > newlines with a space.
Close, but not quite ;-). There may be newlines that need to be preserved, and we are only interested in those newlines that cause our problem, which are newlines embedded in double-quoted strings. strip-quoted-nl: func [string [string!] /local nl-rule] [ nl-rule: [thru {"} to "^/" mark: (change mark " ") thru {"}] parse string [some [nl-rule | skip] ] string ] print-strings-rule: [ set s string! (print mold s) | skip ] parse load strip-quoted-nl read %test-strings.txt [some print-strings-rule] YAA (Yet Another Approach) Elan

 [10/10] from: rgaither:triad:rr at: 26-Feb-2001 17:52


Hi Elan,
>strip-quoted-nl: func [string [string!] /local nl-rule] [ > nl-rule: [thru {"} to "^/" mark: (change mark " ") thru {"}]
<<quoted lines omitted: 5>>
>print-strings-rule] >YAA (Yet Another Approach)
Thanks! All the YAA I've gotten from a simple task has been very helpful. Rod. Rod Gaither Oak Ridge, NC - USA [rgaither--triad--rr--com]

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted