View Issue Details [ Jump to Notes ] | [ Print ] | ||||||||
ID | Project | Category | View Status | Date Submitted | Last Update | ||||
0005380 | CMake | Documentation | public | 2007-07-20 20:53 | 2016-06-10 14:30 | ||||
Reporter | Brandon Van Every | ||||||||
Assigned To | Bill Hoffman | ||||||||
Priority | normal | Severity | text | Reproducibility | always | ||||
Status | closed | Resolution | moved | ||||||
Platform | OS | OS Version | |||||||
Product Version | |||||||||
Target Version | Fixed in Version | ||||||||
Summary | 0005380: REGEX ^ and $ do not match on multi-line <input> | ||||||||
Description | # ^ and $ appear to be non-functional in practice. This makes it # impossible to code a non-trivial regex in CMake script. This in turn # forces the user to find or install other tools that can do so, rather # than keeping their scripting logic self-contained in CMake. # # ^ and $ work work with respect to an entire <input> to STRING(). # That is to say, an <input> is treated as one line. The <input> # does not preserve newlines, even if it is read from a multi-line file. # The following code snippet demonstrates that ^ and $ will only # match at the beginning and end of a file, when the file is read in as # an <input> string. FILE(WRITE in.txt "line0 line1 line2") FILE(READ in.txt stream) STRING(REGEX MATCH "^line0" line0_start "${stream}") STRING(REGEX MATCH "line0$" line0_end "${stream}") STRING(REGEX MATCH "^line1" line1_start "${stream}") STRING(REGEX MATCH "line1$" line1_end "${stream}") STRING(REGEX MATCH "^line2" line2_start "${stream}") STRING(REGEX MATCH "line2$" line2_end "${stream}") MESSAGE("${line0_start}") MESSAGE("${line0_end}") MESSAGE("${line1_start}") MESSAGE("${line1_end}") MESSAGE("${line2_start}") MESSAGE("${line2_end}") #Output: only line0_start and line2_end match. # #C:\in\cbugs>cmake -P regex.cmake #line0 # # # # #line2 # #C:\in\cbugs> | ||||||||
Tags | No tags attached. | ||||||||
Attached Files | |||||||||
Relationships | |
Relationships |
Notes | |
(0008126) Brandon Van Every (reporter) 2007-07-23 09:58 |
A workaround is to use \\r?\\n to match the end of the line. Matching the carriage return 0 or 1 times is necessary because the Unix end of line is just linefeed (LF), but on Windows it's carriage return + linefeed (CR+LF). |
(0009733) Brandon Van Every (reporter) 2007-11-23 13:39 |
Looking at other regular expression libraries, such as PCRE, it appears that not matching line endings when faced with multi-line input is a valid, if regrettable and archaic, implementation choice. Rather than changing CMake's matching behavior, it should be documented. The documentation should warn that the matches do not work on newlines, only the beginning and ends of strings, so that users of "modern" regular expressions know what's going on. |
(0041377) Kitware Robot (administrator) 2016-06-10 14:27 |
Resolving issue as `moved`. This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page. |
Notes |
Issue History | |||
Date Modified | Username | Field | Change |
2007-11-23 13:39 | Brandon Van Every | Note Added: 0009733 | |
2007-11-23 13:39 | Brandon Van Every | Severity | major => text |
2007-11-23 13:49 | Brandon Van Every | Category | CMake => Documentation |
2016-06-10 14:27 | Kitware Robot | Note Added: 0041377 | |
2016-06-10 14:27 | Kitware Robot | Status | assigned => resolved |
2016-06-10 14:27 | Kitware Robot | Resolution | open => moved |
2016-06-10 14:30 | Kitware Robot | Status | resolved => closed |
Issue History |
Copyright © 2000 - 2018 MantisBT Team |