[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4762: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4764: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4765: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4766: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
newlispfanclub.alh.net • View topic - replace
Page 1 of 1

replace

PostPosted: Fri Aug 15, 2003 7:45 pm
by eddier
What variable does replace return the regular expression in "()" in.

I want to do something like the following

(replace {(%[0-9A-F][0-9A-F])} request (char (integer (append "0x" (trim $1) "%"))))

where $1 is the match inside the {()}.

Or if you know a real neat way of converting the %hex values in a cgi request to ASCII?

Eddie

replacing hex codes in a cgi request

PostPosted: Fri Aug 15, 2003 8:00 pm
by eddier
This function works but is brute force! Not very pretty!

(define (replace-hex-codes w)
(join (map (lambda (x) (append (char (integer (append "0x" (slice x 0 2)))) (slice x 2))) (rest (parse text "%"))))))

Eddie

oops

PostPosted: Fri Aug 15, 2003 8:02 pm
by eddier
theargument " w" should be "text" in the function above

PostPosted: Sat Aug 16, 2003 1:31 pm
by Lutz
Before all, don't forget that 'replace' on strings only works in regular expression mode if you add the last options parameter, i.e.

(set 'str "abydxfg")
(replace "x|y" str "e") ;; will not work
(replace "x|y" str "e" 0) ;; will work nicely
(replace "x|y" str "e" 1) ;; will work case insensitive

Replace with regex subexpression is not yet implemented and I hope I will come around to do it one day. Unfortunately 'replace mode seems not to be part of the PCRE package I am using to bild newLISP regular expressions.

But you could use 'regex' to hack something together, because 'regex' returns parenthesized subexpressions:

(set "abcdxfg")
(regex "(..)x" str) -> ("cdx" 2 3 "cd" 2 2)

Now you could use 'slice', 'nth' and concat to compose you new string. But I am not sure that in the case of URL hex translation it will be smaller/faster than your solution, which looks quite elegant (lisp'yish) to me.

The is also a function for hex-code translation in cgi.lsp of the distribution, but your solution seems to be a lot shorter already.

Lutz

PostPosted: Sat Aug 16, 2003 4:25 pm
by eddier

PostPosted: Sat Aug 16, 2003 7:29 pm
by Lutz

PostPosted: Sun Aug 17, 2003 2:28 pm
by eddier

PostPosted: Tue Aug 19, 2003 2:15 am
by Lutz

PostPosted: Tue Aug 19, 2003 3:11 pm
by eddier

PostPosted: Tue Aug 19, 2003 3:51 pm
by Lutz

calendar

PostPosted: Tue Aug 19, 2003 5:27 pm
by eddier