Am 20.05.2015 um 10:35 schrieb Allin Cottrell:
On Tue, 19 May 2015, Sven Schreiber wrote:
In hansl, the only way to create a string that contains nothing but
a
double-quote is to use printf(). Hence the fact that Jack's approach works:
string dq = sprintf("\"")
string s2 = regsub(s1, "\*", dq)
In other words, there's no error in GLib's regexp code, and there isn't
really an error in gretl either -- it's just that at some point in the
past we decided not to mess with escapes in the straight definition of a
string literal, but only via printf.
Ok, but then I don't really understand the need for the co-existence of
strsub() and regsub(). Or to put it differently, why not simply feed the
string arguments in regsub() always through sprintf(), such that
effectively any call regsub(a, b, c) would be handled as
regsub(sprintf(a), sprintf(b), sprintf(c)). Then the distinction between
strsub() and regsub() would be clearcut.
In any case, currently the help text for regsub seems a little
misleading ("The arguments match and repl are interpreted as Perl-style
regular expressions.")
Also, as a lame repeated comment, could the error message somehow give
the user a hint about the underlying problem? For example if the message
said "escape sequences are only handled in the printf() / sprintf()
functions", then the user could replace the literal string, as in:
string s2 = regsub(s1, "\*", sprintf("\""))
(tested and working for s1 == "hu * hu")
thanks,
sven