Re: [CMake] REGEX ^ and $ do not match on multi-line input

2007-07-22 Thread Mathieu Malaterre

Hi Brandon,

 I think you can use this trick to work around your issue:

http://www.cmake.org/pipermail/cmake/2007-May/014317.html

 STRING(REGEX REPLACE \r?\n ; ENT ${input})
 FOREACH(line ${ENT})
 # do the match on each line

HTH
-Mathieu

On 7/21/07, Brandon Van Every [EMAIL PROTECTED] wrote:

I filed this as bug #5380.  Repeating it here in case anyone looks
through the archives for a solution to this problem.
http://cmake.org/Bug/bug.php?op=showbugid=5380pos=17

# ^ 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\cbugscmake -P regex.cmake
#line0
#
#
#
#
#line2
#
#C:\in\cbugs
___
CMake mailing list
CMake@cmake.org
http://www.cmake.org/mailman/listinfo/cmake




--
Mathieu
___
CMake mailing list
CMake@cmake.org
http://www.cmake.org/mailman/listinfo/cmake


Re: [CMake] REGEX ^ and $ do not match on multi-line input

2007-07-22 Thread Brandon Van Every

On 7/22/07, Mathieu Malaterre [EMAIL PROTECTED] wrote:

Hi Brandon,

  I think you can use this trick to work around your issue:

http://www.cmake.org/pipermail/cmake/2007-May/014317.html

  STRING(REGEX REPLACE \r?\n ; ENT ${input})
  FOREACH(line ${ENT})
  # do the match on each line


Thanks for the cross-platform \r\n CR+LF hint.  Last night I tried to
match \n, but it didn't seem to be working.  Actually it was matching
fine, but my output only had \n in it, and a Windows shell needs CR+LF
to go down a line.

Injecting semicolons is really dangerous though.  What if your file
already has semicolons?  In my code, FILE(...) followed by
STRING(REGEX ...) is destroying the semicolons in the file.  I need to
get to the bottom of that.


Cheers,
Brandon Van Every
___
CMake mailing list
CMake@cmake.org
http://www.cmake.org/mailman/listinfo/cmake


[CMake] REGEX ^ and $ do not match on multi-line input

2007-07-21 Thread Brandon Van Every

I filed this as bug #5380.  Repeating it here in case anyone looks
through the archives for a solution to this problem.
http://cmake.org/Bug/bug.php?op=showbugid=5380pos=17

# ^ 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\cbugscmake -P regex.cmake
#line0
#
#
#
#
#line2
#
#C:\in\cbugs
___
CMake mailing list
CMake@cmake.org
http://www.cmake.org/mailman/listinfo/cmake