[CMake] FIND sub-command to the STRING command
Tim Hütz
tim at huetz.biz
Fri Feb 4 10:39:40 EST 2011
Hey Michael,
thanks for the information. Than I'll write some unit tests and attach them too :)
Best,
Tim
Am 04.02.2011 um 16:38 schrieb Michael Wild:
> Very cool.
>
> I think creating a ticket and attaching the patches (or even better,
> posting a URL to a public GIT branch) would be best. In order for this
> feature to be included by Kitware, you'd also need to provide unit tests.
>
>
> Michael
>
> On 02/04/2011 04:31 PM, Tim Hütz wrote:
>> Ok, I've implemented a forward search (finds the first occurrence of the substring) and a reverse search (which finds the last occurrence of a substring). Should I open a ticket (with adding the required paches) for suggesting this for one of the next CMake releases or how should I proceed? The idea of a STRING( FIND REGEX ...) is nice too. I'm working on it as soon as I have some free minutes :)
>>
>> Am 04.02.2011 um 16:02 schrieb Michael Wild:
>>
>>> Exactly. The single-character matching would then just be a special
>>> case. If you want to get fancy, having a string(FIND REGEX) command
>>> would also be nice ;-)
>>>
>>> Michael
>>>
>>> On 02/04/2011 03:31 PM, Tim Hütz wrote:
>>>> 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/ec8de3f1/attachment.pgp>
More information about the CMake
mailing list