MantisBT - CMake
View Issue Details
0010740CMakeCMakepublic2010-05-21 03:262011-11-11 10:45
Rolf Eike Beer 
David Cole 
highfeatureN/A
closedfixed 
CMake-2-8 
CMake 2.8.5CMake 2.8.5 
0010740: STRING(SUBSTRING) should work with length -1
I would like to cut the first character from a string. This means I have to query the string length, substract one and then call:

STRING(SUBSTRING "foo" 1 ${LENGTH} FOO_OUT)

It would be very useful to have a simple way to delete the first N and last N characters. The first could happen by allowing -1 as length:

STRING(SUBSTRING "foo" 1 -1 FOO_OUT) -> "oo"

The other operation could be something like

STRING(CHOP "foo" 1 FOO_OUT) -> "fo"
No tags attached.
patch 0001-allow-STRING-SUBSTRING-work-with-length-1-as-rest-of.patch (2,446) 2010-07-04 13:46
https://public.kitware.com/Bug/file/3223/0001-allow-STRING-SUBSTRING-work-with-length-1-as-rest-of.patch
patch 0002-add-STRING-CHOP-command.patch (4,920) 2010-07-04 13:46
https://public.kitware.com/Bug/file/3224/0002-add-STRING-CHOP-command.patch
patch 0001-update-documentation-of-STRING-SUBSTRING-for-length-.patch (2,062) 2011-02-03 15:11
https://public.kitware.com/Bug/file/3675/0001-update-documentation-of-STRING-SUBSTRING-for-length-.patch
Issue History
2010-05-21 03:26Rolf Eike BeerNew Issue
2010-07-04 13:46Rolf Eike BeerFile Added: 0001-allow-STRING-SUBSTRING-work-with-length-1-as-rest-of.patch
2010-07-04 13:46Rolf Eike BeerFile Added: 0002-add-STRING-CHOP-command.patch
2010-07-04 13:47Rolf Eike BeerNote Added: 0021234
2010-07-04 13:48Rolf Eike BeerNote Added: 0021235
2010-08-31 17:12David ColeStatusnew => assigned
2010-08-31 17:12David ColeAssigned To => David Cole
2010-08-31 17:50David ColeTarget Version => CMake 2.8.3
2010-09-07 17:24David ColeNote Added: 0022116
2010-09-07 17:24David ColeTarget VersionCMake 2.8.3 =>
2010-09-07 17:31Rolf Eike BeerNote Added: 0022117
2010-09-07 17:36David ColeNote Added: 0022118
2010-09-09 17:59David ColePrioritynormal => high
2010-11-10 21:09David ColeTarget Version => CMake 2.8.4
2010-12-08 14:50Ben BoeckelAssigned ToDavid Cole => Ben Boeckel
2010-12-08 16:52Ben BoeckelNote Added: 0023825
2010-12-09 16:10Rolf Eike BeerNote Added: 0023858
2010-12-09 16:17Ben BoeckelNote Added: 0023859
2010-12-09 16:26David ColeNote Added: 0023860
2011-01-06 14:39Ben BoeckelNote Added: 0024473
2011-01-06 14:39Ben BoeckelStatusassigned => resolved
2011-01-06 14:39Ben BoeckelResolutionopen => fixed
2011-01-06 14:39Ben BoeckelFixed in Version => CMake 2.8.4
2011-02-03 05:40Rolf Eike BeerNote Added: 0025229
2011-02-03 05:40Rolf Eike BeerStatusresolved => feedback
2011-02-03 05:40Rolf Eike BeerResolutionfixed => reopened
2011-02-03 15:11Rolf Eike BeerFile Added: 0001-update-documentation-of-STRING-SUBSTRING-for-length-.patch
2011-02-16 11:33David ColeTarget VersionCMake 2.8.4 => CMake 2.8.5
2011-05-25 17:18David ColeAssigned ToBen Boeckel => David Cole
2011-05-25 17:18David ColeStatusfeedback => assigned
2011-05-25 17:19David ColeNote Added: 0026599
2011-05-26 07:06Rolf Eike BeerNote Added: 0026615
2011-05-26 07:29David ColeNote Added: 0026616
2011-06-05 14:30David ColeNote Added: 0026671
2011-06-05 14:30David ColeStatusassigned => resolved
2011-06-05 14:30David ColeFixed in VersionCMake 2.8.4 => CMake 2.8.5
2011-06-05 14:30David ColeResolutionreopened => fixed
2011-11-11 10:45David ColeNote Added: 0027759
2011-11-11 10:45David ColeStatusresolved => closed

Notes
(0021234)
Rolf Eike Beer   
2010-07-04 13:47   
These patches (based on efee95cd710808ca7ac261359b9b8e6dacb09211) implement both things and add testcases to make sure that works as expected.
(0021235)
Rolf Eike Beer   
2010-07-04 13:48   
Please replace the From line with

From: Rolf Eike Beer <eike@sf-mail.de>

before applying.
(0022116)
David Cole   
2010-09-07 17:24   
Changing target version... Since there is a way to accomplish this with existing CMake and this is merely a "convenience" feature request, and it is a new feature.... I'm delaying the implementation for this issue to a future release (not for 2.8.3). CMake devs do not have enough time left before 2.8.3 to work on this issue.

I don't like the word "CHOP" and I'm not sure that we should extend SUBSTRING to use "-1" as meaning "the rest of the string". Or at least use the word "truncate" rather than chop. Truncate has a specific meaning of chopping off the end, whereas chop could mean chop off either end.

Even better, though, I think it would be more clear to introduce new methods in the string command for string(LEFT and string(RIGHT.
(0022117)
Rolf Eike Beer   
2010-09-07 17:31   
I just took the "chop" from Qt's QString, I don't have any objections against truncate.

RIGHT and LEFT would still not solve the "issue" to just remove the first n characters without checking the length first.
(0022118)
David Cole   
2010-09-07 17:36   
Certainly for now, you could write a function or macro in the CMake language that performs these operations in a more elegant manner... but uses MATH and SUBSTRING under the hood.
(0023825)
Ben Boeckel   
2010-12-08 16:52   
I applied the substring patch. Is there some reason to apply the CHOP (or an equivalent) without a mirror version to take from the beginning of the string? A RIGHT and LEFT would suffice for that I'd think.
(0023858)
Rolf Eike Beer   
2010-12-09 16:10   
Well, that substring one is basically the opposite of the CHOP. We could make CHOP_RIGHT and CHOP_LEFT (or whatever) from them. Or any better name one could imagine. I can't ;)
(0023859)
Ben Boeckel   
2010-12-09 16:17   
The patch that was attached added -1 as "rest of string" so that would conflict with a meaning of going backwards in the string. Alternatively, a value of 0 could mean "rest of string" as a length of 0 is no different then setting a variable to the empty string, but this breaks backwards compatibility and is probably not a valid solution for CMake. I'll look at implementing RIGHT and LEFT. Maybe FIRST and LAST as names?
(0023860)
David Cole   
2010-12-09 16:26   
There's no need for LEFT or FIRST:
string(LEFT 5 ...)

because it's equivalent to:
string(SUBSTRING 0 5 ...)

But it probably doesn't make sense to provide a RIGHT if there is no LEFT...

Coming up with the proper names here is critical for this issue. It should "do what it's named" so that 99.9% of people who encounter just know what it does without looking up the documentation.
(0024473)
Ben Boeckel   
2011-01-06 14:39   
Merged into master.

http://cmake.org/gitweb?p=cmake.git;a=commit;h=2d1aa4ad06eedf6bc677c8ebf757f4978a839e02 [^]
(0025229)
Rolf Eike Beer   
2011-02-03 05:40   
There are some error messages in the C++ file and the documentation that need to reflect the change. I'll cook up a patch tonight.
(0026599)
David Cole   
2011-05-25 17:19   
Hi Rolf,

Have any patches been cooked up?

What error messages need to change?
(0026615)
Rolf Eike Beer   
2011-05-26 07:06   
https://public.kitware.com/Bug/file/3675/0001-update-documentation-of-STRING-SUBSTRING-for-length-.patch [^]
(0026616)
David Cole   
2011-05-26 07:29   
Ah, thanks. I didn't notice that a patch had been attached after your previous note...
(0026671)
David Cole   
2011-06-05 14:30   
Documentation updated in this commit:

  http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=ecdad65a4541db353bd498be7d7090b5ed059ebc [^]
(0027759)
David Cole   
2011-11-11 10:45   
Closing resolved issues that have not been updated in more than 4 months.