View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0011795CMakeCMakepublic2011-02-04 11:262011-06-17 18:25
ReporterTim Hütz 
Assigned ToBrad King 
PrioritynormalSeverityminorReproducibilityN/A
StatusclosedResolutionfixed 
PlatformOSOS Version
Product Version 
Target VersionCMake 2.8.5Fixed in VersionCMake 2.8.5 
Summary0011795: Extending the STRING command with a FIND sub-command
DescriptionRecently I was searching for a CMake option to get the position of a single character (first appearance) out of a string. As I found nothing which could provide me an easy solution, I pulled the latest development version and added a FIND sub-command to the STRING command.

The attached patch supports a forward search (finds the first occurrence of the substring) and a reverse search (which finds the last occurrence of a substring).

Here is a sample how the sub-commands works:

-----

project( "STRING FIND command" )
cmake_minimum_required(VERSION 2.8)

set( TESTSTRING "This is a test and here is another test." )
string( FIND ${TESTSTRING} "a" APOSITION )
string( FIND REVERSE ${TESTSTRING} "a" APOSITIONREV )
message( STATUS "Firt position of character 'a' (8) is ${APOSITION}" )
message( STATUS "Last position of character 'a' (27) is ${APOSITIONREV}" )

-----

I've already discussed this sub-command on the CMake mailing list (http://www.cmake.org/pipermail/cmake/2011-February/042521.html [^]).

Maybe, this would be a nice feature for one of the next CMake releases.

Best regards,
Tim
TagsNo tags attached.
Attached Filespatch file icon 0002-Added-tests-for-the-FIND-sub-command-of-STRING.patch [^] (4,051 bytes) 2011-02-15 05:27 [Show Content]
patch file icon 0001-Added-a-new-STRING-sub-command-called-FIND.patch [^] (4,694 bytes) 2011-02-15 09:15 [Show Content]
patch file icon 0003-Updated-the-tests-for-the-new-signature-of-STRING-FI.patch [^] (4,281 bytes) 2011-02-15 11:52 [Show Content]
patch file icon 0004-Changed-the-signature-of-the-FIND-sub-command.patch [^] (2,921 bytes) 2011-02-15 11:52 [Show Content]

 Relationships

  Notes
(0025286)
Tim Hütz (reporter)
2011-02-04 12:52
edited on: 2011-02-04 12:52

Sorry, I've posted the wrong link. The correct one is http://www.cmake.org/pipermail/cmake/2011-February/042523.html [^]

(0025426)
Brad King (manager)
2011-02-14 16:46

Please add a test for this feature. You can probably modify one of these two files:

  Tests/CMakeTests/StringTest.cmake.in
  Tests/StringFileTest/CMakeLists.txt

Thanks.
(0025428)
Tim Hütz (reporter)
2011-02-15 05:30

Hey Brad,

I've created several test cases and attached a patch for them. While I was writing those tests, I found some bugs in my code and I fixed them. Unfortunately I cannot delete the old patch (0001) to submit the new one. Am I not allowed to delete my own attachments or am I just blind to finds such a function? As soon as the old patch is gone, I'll upload the fixed one.

Best regards,
Tim
(0025430)
Brad King (manager)
2011-02-15 07:44

I deleted the old patch for you. I think the issue tracker is configured to only allow developers to delete attachments. I don't think it cares who created them. Typically folks just rename the file with -2 at the end or something to upload a new one.
(0025433)
Tim Hütz (reporter)
2011-02-15 09:16

Thanks for deleting the old patch. I've uploaded the new one (with the included bug fixes).
(0025435)
Brad King (manager)
2011-02-15 09:35

One of the problems with CMake's ad-hoc keyword-based arguments is ambiguity so care needs to be taken in new command signatures. What happens if I want to search for the string "REVERSE"? I can imagine people in the future wanting "find starting at position N" and other things that come from the std::string interface. While string processing is not a goal of the CMake language I'd like to leave the interface open to such extensions unambiguously.

Perhaps the signature should be

  string(FIND <str> <substr> <outvar> [REVERSE] [future options here...])
(0025439)
Tim Hütz (reporter)
2011-02-15 11:53
edited on: 2011-02-15 11:55

Thanks for your suggestion. I updated the tests and the sub-command implementation itself. The two new patches base on the previous two. Now the command signature is as you suggested:

string(FIND <str> <substr> <outvar> [REVERSE])

(0025444)
Brad King (manager)
2011-02-15 13:51

Applied with minor edits:

  http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=1462561a [^]

Thanks for your work!

 Issue History
Date Modified Username Field Change
2011-02-04 11:26 Tim Hütz New Issue
2011-02-04 11:26 Tim Hütz File Added: 0001-Added-a-new-STRING-sub-command-called-FIND.patch
2011-02-04 12:52 Tim Hütz Note Added: 0025286
2011-02-04 12:52 Tim Hütz Note Edited: 0025286
2011-02-14 16:46 Brad King Note Added: 0025426
2011-02-15 05:27 Tim Hütz File Added: 0002-Added-tests-for-the-FIND-sub-command-of-STRING.patch
2011-02-15 05:30 Tim Hütz Note Added: 0025428
2011-02-15 07:43 Brad King File Deleted: 0001-Added-a-new-STRING-sub-command-called-FIND.patch
2011-02-15 07:44 Brad King Note Added: 0025430
2011-02-15 09:15 Tim Hütz File Added: 0001-Added-a-new-STRING-sub-command-called-FIND.patch
2011-02-15 09:16 Tim Hütz Note Added: 0025433
2011-02-15 09:29 Brad King Assigned To => Brad King
2011-02-15 09:29 Brad King Status new => assigned
2011-02-15 09:35 Brad King Note Added: 0025435
2011-02-15 11:52 Tim Hütz File Added: 0003-Updated-the-tests-for-the-new-signature-of-STRING-FI.patch
2011-02-15 11:52 Tim Hütz File Added: 0004-Changed-the-signature-of-the-FIND-sub-command.patch
2011-02-15 11:53 Tim Hütz Note Added: 0025439
2011-02-15 11:55 Tim Hütz Note Edited: 0025439
2011-02-15 13:51 Brad King Note Added: 0025444
2011-02-15 13:51 Brad King Status assigned => closed
2011-02-15 13:51 Brad King Resolution open => fixed
2011-02-16 11:40 David Cole Target Version => CMake 2.8.5
2011-06-17 18:25 David Cole Fixed in Version => CMake 2.8.5


Copyright © 2000 - 2018 MantisBT Team