WeiDUorg / weidu

WeiDU is a program used to develop, distribute and install modifications for games based on the Infinity Engine.
http://www.weidu.org
GNU General Public License v2.0
87 stars 19 forks source link

COUNT_REGEXP_INSTANCES vs. empty files #219

Closed 4Luke4 closed 9 months ago

4Luke4 commented 1 year ago

According to the documentation, this command is supposed to return the number of times regexp appears in the current file.

However, if the current file is empty, it returns -1 instead of 0.

Steps to reproduce

OUTER_PATCH ~a~ BEGIN
    COUNT_REGEXP_INSTANCES CASE_INSENSITIVE EVALUATE_REGEXP "\bwhatever\b" "count"
END
PRINT ~%count%~ // will print 0 (OK)
OUTER_PATCH ~~ BEGIN
    COUNT_REGEXP_INSTANCES CASE_INSENSITIVE EVALUATE_REGEXP "\bwhatever\b" "count"
END
PRINT ~%count%~ // will print -1 (OK...?)

Is it intended...?

FredrikLindgren commented 9 months ago

I would say undefined behaviour. It's returning -1 on an empty file and 0 on a file with no matches due to an implementation detail. What's desired behaviour?

4Luke4 commented 9 months ago

I would say undefined behaviour. It's returning -1 on an empty file and 0 on a file with no matches due to an implementation detail. What's desired behaviour?

Up to you I guess... I mean, it is easy to workaround, so you might want to keep things as they are... If that is the case, then you might want to clarify the undefined behaviour in the docs...