guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] add new read-delimited option to return #f while terminating del


From: Nala Ginrut
Subject: [PATCH] add new read-delimited option to return #f while terminating delimiter can't be found.
Date: Thu, 8 Mar 2012 00:32:59 +0800

I found current read-delimited will return the whole string if delimiter can't be found. It's inconvenient for some cases.
I expect it return #f for this.
And Andy said it maybe because some back compatible reasons. So I decide to add an option to do this job. 
If we use the original version, we must do this:
-----------------------------------cut-----------------------------------------------------
(let ((token (call-with-input-string "asdf" (lambda (port) (read-delimited "@" port 'split)))))
    (if (eof-object? (cdr token))
         ""
         (car token)))
-----------------------------------end----------------------------------------------------
It's rather ugly.

Now it's better:
-----------------------------------cut-----------------------------------------------------
(call-with-input-string "asdf" (lambda (port) (read-delimited "@" port 'fail))))
==> #f
(call-with-input-string "address@hidden" (lambda (port) (read-delimited "@" port 'fail))))
==> "as"
-----------------------------------end----------------------------------------------------
If delimiter exists, it works like 'trim mode.

Comments?

Regards.

Attachment: 0001-add-an-option-to-let-read-delimited-return-false-whi.patch
Description: Text Data

Attachment: 0002-Add-new-handle-delim-option-fail-to-the-manual.patch
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]