[CMake] FIND sub-command to the STRING command
Tim Hütz
tim at huetz.biz
Fri Feb 4 09:31:07 EST 2011
Mhh, okay. With substring matching you mean that I can get the position of the first occurrence of a word or sub-sentence, am I right?
Am 04.02.2011 um 13:32 schrieb Michael Wild:
> On 02/04/2011 12:49 PM, Tim Hütz wrote:
>> I don't think that the speed-factor was important in this case. A complete CMake run takes about 25 seconds to run (in my case) and I see no influence in the processing time with my suggested patch or the regular expression sample provided by Michael. I thought that my solution is a bit more intuitive, but I don't know if this is really important for CMake. If you use the provided patch, you can do something like
>>
>> PROJECT( "STRING FIND command" )
>> SET( TESTSTRING "This is a test" )
>> STRING( FIND ${TESTSTRING} "a" APOSITION )
>> MESSAGE( STATUS "Position of character 'a' is ${APOSITION}" )
>>
>> Regards,
>> Tim
>>
>> Am 04.02.2011 um 12:00 schrieb SF Markus Elfring:
>>
>>>> mhh, yeah, thats a good idea. Ok, I'll use this for doing a "STRING( FIND ...)" :) It was just an idea to share this patch with you, but you're right. Its easier doing this with regular expressions.
>>>
>>> Can it be that your implementation was faster than a complete regex application for your use case?
>>>
>>> Are there any remarkable differences in the corresponding execution speed and performance characteristics?
>>>
>>> Regards,
>
> I just wanted to point out that this particular use-case can be handled
> by a regular expression. I still think that a string(FIND) command would
> be useful, although it would be even more so if it did substring matching.
>
> BTW, I just had an idea how to find substrings with regexes, but it is
> even more tedious:
>
> set(str "Hello Tim. How are you Tim?")
> set(pos -1)
> if(str MATCHES "(Tim.*)")
> string(LENGTH "${str}" l1)
> string(LENGTH "${CMAKE_MATCH_1}" l2)
> math(EXPR pos "${l1}-${l2}")
> endif()
>
> This finds the position of the first occurence of "Tim". Another
> alternative, without math(EXPR) is:
>
> set(str "Hello Tim. How are you Tim?")
> set(pos -1)
> string(REGEX REPLACE "Ali.*" "" tmp "${str}")
> if(NOT "${tmp}" STREQUAL "${str}")
> string(LENGTH "${tmp}" pos)
> endif()
>
> Michael
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 833 bytes
Desc: Signierter Teil der Nachricht
URL: <http://www.cmake.org/pipermail/cmake/attachments/20110204/68172033/attachment.pgp>
More information about the CMake
mailing list