hyperrealm / libconfig

C/C++ library for processing configuration files
https://hyperrealm.github.io/libconfig/
GNU Lesser General Public License v2.1
1.1k stars 360 forks source link

Fixed project version escape character #161

Closed AbitTheGray closed 4 years ago

AbitTheGray commented 4 years ago
\\ -> \
\t -> Tab Key
\. -> INVALID

\. does not escape . on Regex Level but on string level. To escape . on Regex level, you need to send \. to Regex which is \\. on string level (can be very confusing when you need to escape \ on Regex level resulting in \\\\ on string level).

Did not notice this myself but CLion showed me this as an error.

thomastrapp commented 4 years ago

From your pull request:

set(VERSION_REGEX "^AC_INIT\\(libconfig,[ \t]+([0-9\\.]+),.*")

The string ([0-9\\.]+) will be translated to the regex ([0-9\.]+), which matches 0-9, literal ., but also \.

. don't need to be escaped inside character groups (e.g. [.]+ will match only literal dots). This is why the original string ([0-9\.]+) was working as expected. CLion is right to complain that \. will result in . at the regex level.

Therefore, I think the escape character should be removed:

set(VERSION_REGEX "^AC_INIT\\(libconfig,[ \t]+([0-9.]+),.*")

I used cmake v3.10.2 to check.

AbitTheGray commented 4 years ago

OK, removed the backslash in new commit.