unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* string splitting
@ 2012-02-20 18:51 Catonano
  2012-02-20 18:52 ` Catonano
  2012-02-21  9:53 ` Andy Wingo
  0 siblings, 2 replies; 7+ messages in thread
From: Catonano @ 2012-02-20 18:51 UTC (permalink / raw)
  To: guile-user

[-- Attachment #1: Type: text/plain, Size: 298 bytes --]

Hello people,

I'd love to split a url string. Is there a function I am supposed to use ?
In which module ?

that is

"...blah/blah?param1=1234&param2=5678"

should become

("...blah/blah?param1=1234" "param2=5678")

I have extracted the source string from a htmlprag tree

Thanks for any hint

[-- Attachment #2: Type: text/html, Size: 387 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: string splitting
  2012-02-20 18:51 string splitting Catonano
@ 2012-02-20 18:52 ` Catonano
  2012-02-21  7:37   ` Thien-Thi Nguyen
  2012-02-21  9:53 ` Andy Wingo
  1 sibling, 1 reply; 7+ messages in thread
From: Catonano @ 2012-02-20 18:52 UTC (permalink / raw)
  To: guile-user

[-- Attachment #1: Type: text/plain, Size: 139 bytes --]

I just found this
http://www.gnu.org/software/guile/manual/html_node/List_002fString-Conversion.html#List_002fString-Conversion

I'm sorry

[-- Attachment #2: Type: text/html, Size: 283 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: string splitting
  2012-02-20 18:52 ` Catonano
@ 2012-02-21  7:37   ` Thien-Thi Nguyen
  0 siblings, 0 replies; 7+ messages in thread
From: Thien-Thi Nguyen @ 2012-02-21  7:37 UTC (permalink / raw)
  To: Catonano; +Cc: guile-user

() Catonano <catonano@gmail.com>
() Mon, 20 Feb 2012 19:52:46 +0100

   I just found this [...]

See also Guile-WWW modules ‘(www url)’ and ‘(www cgi)’:

http://www.nongnu.org/guile-www/doc/url.html
http://www.nongnu.org/guile-www/doc/cgi.html



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: string splitting
  2012-02-20 18:51 string splitting Catonano
  2012-02-20 18:52 ` Catonano
@ 2012-02-21  9:53 ` Andy Wingo
  2012-02-22 10:36   ` Catonano
  1 sibling, 1 reply; 7+ messages in thread
From: Andy Wingo @ 2012-02-21  9:53 UTC (permalink / raw)
  To: Catonano; +Cc: guile-user

On Mon 20 Feb 2012 19:51, Catonano <catonano@gmail.com> writes:

> I'd love to split a url string. Is there a function I am supposed to use ? In which module ?
>
> that is
>
> "...blah/blah?param1=1234&amp;param2=5678"

Use (web uri).  Specifically string->uri and uri-query.

Once you have the query string, you can pick apart the pieces with
something like this:

  (define* (parse-www-form-urlencoded str #:optional (charset "utf-8"))
    (map
     (lambda (piece)
       (let ((equals (string-index piece #\=)))
         (if equals
             (cons (uri-decode (substring piece 0 equals) #:encoding charset)
                   (uri-decode (substring piece (1+ equals)) #:encoding charset))
             (cons (uri-decode piece #:encoding charset) ""))))
     (string-split str #\&)))

Andy
-- 
http://wingolog.org/



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: string splitting
  2012-02-21  9:53 ` Andy Wingo
@ 2012-02-22 10:36   ` Catonano
  2012-02-22 11:23     ` Andy Wingo
  0 siblings, 1 reply; 7+ messages in thread
From: Catonano @ 2012-02-22 10:36 UTC (permalink / raw)
  To: Andy Wingo; +Cc: guile-user

[-- Attachment #1: Type: text/plain, Size: 526 bytes --]

Thanks to the both of you but it seems I couldn't anage to make my
intentions clear

Andy, when given my string, your function returns

(("blah/blah?param1" . "123") ("amp;param2" . "456"))

which is not what I want.

What I wanted is to get

"blah/blah?param1=123&param2=456

FROM

"blah/blah?param1=123&amp;param2=456

Since &amp; is a standard html extended symbol I was hoping that htmlprag
would have dealt with it for me. But I solved anyway.

Thanks

Now I have a new issue but I'll write about it in a new thread

Bye

[-- Attachment #2: Type: text/html, Size: 674 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: string splitting
  2012-02-22 10:36   ` Catonano
@ 2012-02-22 11:23     ` Andy Wingo
  2012-02-22 11:47       ` Catonano
  0 siblings, 1 reply; 7+ messages in thread
From: Andy Wingo @ 2012-02-22 11:23 UTC (permalink / raw)
  To: Catonano; +Cc: guile-user

On Wed 22 Feb 2012 11:36, Catonano <catonano@gmail.com> writes:

> Andy, when given my string, your function returns
>
> (("blah/blah?param1" . "123") ("amp;param2" . "456"))

You have two problems here.  One is that you need to be running it as

  (parse-www-form-urlencoded (uri-query (string->uri uri)))

> What I wanted is to get
>
> "blah/blah?param1=123&param2=456
>
> FROM
>
> "blah/blah?param1=123&amp;param2=456

Here, Htmlprag should be turning the &amp; into &.  If it's not doing
that, that's a problem.

First you parse HTML, expanding parsed entities (&foo;).  Then you parse
the URI.  Then you parse the query part.

Andy
-- 
http://wingolog.org/



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: string splitting
  2012-02-22 11:23     ` Andy Wingo
@ 2012-02-22 11:47       ` Catonano
  0 siblings, 0 replies; 7+ messages in thread
From: Catonano @ 2012-02-22 11:47 UTC (permalink / raw)
  To: guile-user

[-- Attachment #1: Type: text/plain, Size: 621 bytes --]

Andy,

Il giorno 22 febbraio 2012 12:23, Andy Wingo <wingo@pobox.com> ha scritto:

> You have two problems here.  One is that you need to be running it as
>
>  (parse-www-form-urlencoded (uri-query (string->uri uri)))
>
>
Ok

First you parse HTML, expanding parsed entities (&foo;).  Then you parse
> the URI.  Then you parse the query part.
>
>
I get it ;-) Yes, admittedly, at the moment in my solution the step to
isolate the query part of the string is missing, I parse the whole url
string. I can quickly fix that.

And I appreciate your acknowledgement that there could be a problem in
htmlprag.

Thanks again

Bye

[-- Attachment #2: Type: text/html, Size: 1147 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2012-02-22 11:47 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-20 18:51 string splitting Catonano
2012-02-20 18:52 ` Catonano
2012-02-21  7:37   ` Thien-Thi Nguyen
2012-02-21  9:53 ` Andy Wingo
2012-02-22 10:36   ` Catonano
2012-02-22 11:23     ` Andy Wingo
2012-02-22 11:47       ` Catonano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).