[cmake-developers] string SUBSTRING TRUNCATE mode

Domen Vrankar domen.vrankar at gmail.com
Tue Nov 11 18:16:16 EST 2014


Hi,

I wrote a patch that adds functionality to string SUBSTRING command:

string(SUBSTRING <string> <begin> <length> <output variable> [TRUNCATE])

When TRUNCATE is set this is valid:

cmake_minimum_required (VERSION 3.0)
project(string_test)
set(test_str "abcd")
string(SUBSTRING ${test_str} 2 6 substr TRUNCATE)
message(${test_str})
message(${substr})

If length is set to a higher value than the length of the original
string the substring is still created but its end is the end of
original string.

If this functionality would be welcome I'll write the tests and documentation.

TRUNCATE could also be renamed to SHORTEN or something more
appropriate since we aren't truncating the string but are just
lowering the length parameter. Suggestions are welcome.

Thanks,
Domen
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-String-substring-truncate.patch
Type: text/x-diff
Size: 2559 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20141112/2007a026/attachment.patch>


More information about the cmake-developers mailing list