Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2020-02

Last fix for RegExpr (error on empty input)

5 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

AlexeyT

1) typo in new Id: iMput.

2) wrong fix for 2nd "Error" call in Substitute(): you disabled Error call but didn't disable Exit, you need to skip Exit there too, so Substitute will return non empty result when user replaces regex "\b" to e.g. "__".

Regards, Alexey

Reply by email

Michael Van Canneyt
to AlexeyT
AlexeyT wrote
1) typo in new Id: iMput.

Indeed, I looked right over that. I fixed that.

Show quoted text 5 lines
2) wrong fix for 2nd "Error" call in Substitute(): you disabled Error call but didn't disable Exit, you need to skip Exit there too, so Substitute will return non empty result when user replaces regex "\b" to e.g. "__".

I read your comment, but I am not sure that this is desirable behaviour.

For example sed also does not consider the empty string a word boundary:

home:~> echo '' | sed s/\\b/x/g

home:~> echo 'a' | sed s/\\b/x/g
xax

For empty string, it does not change anything. I think this is correct, because there is no word, so there also cannot be a word boundary.

So I preferred not to change this behaviour.

Michael.

Reply by email

AlexeyT
to Michael Van Canneyt

My app does mass replace with regex. in big text, user enters regex "\b" and replaces it to eg "__". app calls Substitute() with each found match, match is zero length so your code will NOT replace it to "__". but it's needed to replace it to "__".

Regards, Alexey

Reply by email

Michael Van Canneyt
to AlexeyT
AlexeyT wrote
My app does mass replace with regex. in big text, user enters regex "\b" and replaces it to eg "__". app calls Substitute() with each found match, match is zero length so your code will NOT replace it to "__". but it's needed to replace it to "__".

That can well be, but maybe in that case you need to change your app for this particular use case. It's very much a corner case.

The alternative is to introduce a new boolean option for TRegexp which controls the behaviour of substitute.

Since there are already 9 boolean properties, it may be better to introduce a Options set property and mark the others deprecated.

Michael.

Reply by email