[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

replace

Q&A's, tips, howto's

replace

Postby eddier » Fri Aug 15, 2003 7:45 pm

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
eddier
 
Posts: 289
Joined: Mon Oct 07, 2002 2:48 pm
Location: Blue Mountain College, MS US

replacing hex codes in a cgi request

Postby eddier » Fri Aug 15, 2003 8:00 pm

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
eddier
 
Posts: 289
Joined: Mon Oct 07, 2002 2:48 pm
Location: Blue Mountain College, MS US

oops

Postby eddier » Fri Aug 15, 2003 8:02 pm

theargument " w" should be "text" in the function above
eddier
 
Posts: 289
Joined: Mon Oct 07, 2002 2:48 pm
Location: Blue Mountain College, MS US

Postby Lutz » Sat Aug 16, 2003 1:31 pm

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
Lutz
 
Posts: 5279
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California

Postby eddier » Sat Aug 16, 2003 4:25 pm

eddier
 
Posts: 289
Joined: Mon Oct 07, 2002 2:48 pm
Location: Blue Mountain College, MS US

Postby Lutz » Sat Aug 16, 2003 7:29 pm

Lutz
 
Posts: 5279
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California

Postby eddier » Sun Aug 17, 2003 2:28 pm

eddier
 
Posts: 289
Joined: Mon Oct 07, 2002 2:48 pm
Location: Blue Mountain College, MS US

Postby Lutz » Tue Aug 19, 2003 2:15 am

Lutz
 
Posts: 5279
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California

Postby eddier » Tue Aug 19, 2003 3:11 pm

eddier
 
Posts: 289
Joined: Mon Oct 07, 2002 2:48 pm
Location: Blue Mountain College, MS US

Postby Lutz » Tue Aug 19, 2003 3:51 pm

Lutz
 
Posts: 5279
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California

calendar

Postby eddier » Tue Aug 19, 2003 5:27 pm

eddier
 
Posts: 289
Joined: Mon Oct 07, 2002 2:48 pm
Location: Blue Mountain College, MS US


Return to newLISP in the real world

Who is online

Users browsing this forum: No registered users and 1 guest