string: add APPEND subcommand
This commit is contained in:
parent
7e86f567ac
commit
2b18cdcaba
@ -15,6 +15,7 @@ String operations.
|
|||||||
string(REPLACE <match_string>
|
string(REPLACE <match_string>
|
||||||
<replace_string> <output variable>
|
<replace_string> <output variable>
|
||||||
<input> [<input>...])
|
<input> [<input>...])
|
||||||
|
string(APPEND <string variable> [<input>...])
|
||||||
string(CONCAT <output variable> [<input>...])
|
string(CONCAT <output variable> [<input>...])
|
||||||
string(<MD5|SHA1|SHA224|SHA256|SHA384|SHA512>
|
string(<MD5|SHA1|SHA224|SHA256|SHA384|SHA512>
|
||||||
<output variable> <input>)
|
<output variable> <input>)
|
||||||
@ -55,6 +56,8 @@ through argument parsing.
|
|||||||
``REPLACE`` will replace all occurrences of ``match_string`` in the input
|
``REPLACE`` will replace all occurrences of ``match_string`` in the input
|
||||||
with ``replace_string`` and store the result in the output.
|
with ``replace_string`` and store the result in the output.
|
||||||
|
|
||||||
|
``APPEND`` will append all the input arguments to the string.
|
||||||
|
|
||||||
``CONCAT`` will concatenate all the input arguments together and store
|
``CONCAT`` will concatenate all the input arguments together and store
|
||||||
the result in the named output variable.
|
the result in the named output variable.
|
||||||
|
|
||||||
|
4
Help/release/dev/string-append.rst
Normal file
4
Help/release/dev/string-append.rst
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
string-append
|
||||||
|
-------------
|
||||||
|
|
||||||
|
* The :command:`string` command learned a new ``APPEND`` subcommand.
|
@ -74,6 +74,10 @@ bool cmStringCommand
|
|||||||
{
|
{
|
||||||
return this->HandleLengthCommand(args);
|
return this->HandleLengthCommand(args);
|
||||||
}
|
}
|
||||||
|
else if(subCommand == "APPEND")
|
||||||
|
{
|
||||||
|
return this->HandleAppendCommand(args);
|
||||||
|
}
|
||||||
else if(subCommand == "CONCAT")
|
else if(subCommand == "CONCAT")
|
||||||
{
|
{
|
||||||
return this->HandleConcatCommand(args);
|
return this->HandleConcatCommand(args);
|
||||||
@ -729,6 +733,34 @@ bool cmStringCommand
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
bool cmStringCommand::HandleAppendCommand(std::vector<std::string> const& args)
|
||||||
|
{
|
||||||
|
if(args.size() < 2)
|
||||||
|
{
|
||||||
|
this->SetError("sub-command APPEND requires at least one argument.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skip if nothing to append.
|
||||||
|
if(args.size() < 3)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string& variable = args[1];
|
||||||
|
|
||||||
|
std::string value;
|
||||||
|
const char* oldValue = this->Makefile->GetDefinition(variable);
|
||||||
|
if(oldValue)
|
||||||
|
{
|
||||||
|
value = oldValue;
|
||||||
|
}
|
||||||
|
value += cmJoin(cmRange(args).advance(2), std::string());
|
||||||
|
this->Makefile->AddDefinition(variable, value.c_str());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
bool cmStringCommand
|
bool cmStringCommand
|
||||||
::HandleConcatCommand(std::vector<std::string> const& args)
|
::HandleConcatCommand(std::vector<std::string> const& args)
|
||||||
|
@ -67,6 +67,7 @@ protected:
|
|||||||
bool HandleReplaceCommand(std::vector<std::string> const& args);
|
bool HandleReplaceCommand(std::vector<std::string> const& args);
|
||||||
bool HandleLengthCommand(std::vector<std::string> const& args);
|
bool HandleLengthCommand(std::vector<std::string> const& args);
|
||||||
bool HandleSubstringCommand(std::vector<std::string> const& args);
|
bool HandleSubstringCommand(std::vector<std::string> const& args);
|
||||||
|
bool HandleAppendCommand(std::vector<std::string> const& args);
|
||||||
bool HandleConcatCommand(std::vector<std::string> const& args);
|
bool HandleConcatCommand(std::vector<std::string> const& args);
|
||||||
bool HandleStripCommand(std::vector<std::string> const& args);
|
bool HandleStripCommand(std::vector<std::string> const& args);
|
||||||
bool HandleRandomCommand(std::vector<std::string> const& args);
|
bool HandleRandomCommand(std::vector<std::string> const& args);
|
||||||
|
58
Tests/RunCMake/string/Append.cmake
Normal file
58
Tests/RunCMake/string/Append.cmake
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
set(out)
|
||||||
|
string(APPEND out)
|
||||||
|
if(DEFINED out)
|
||||||
|
message(FATAL_ERROR "\"string(APPEND out)\" set out to \"${out}\"")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(out "")
|
||||||
|
string(APPEND out)
|
||||||
|
if(NOT out STREQUAL "")
|
||||||
|
message(FATAL_ERROR "\"string(APPEND out)\" set out to \"${out}\"")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(out x)
|
||||||
|
string(APPEND out)
|
||||||
|
if(NOT out STREQUAL "x")
|
||||||
|
message(FATAL_ERROR "\"string(APPEND out)\" set out to \"${out}\"")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
set(out)
|
||||||
|
string(APPEND out a)
|
||||||
|
if(NOT out STREQUAL "a")
|
||||||
|
message(FATAL_ERROR "\"string(APPEND out a)\" set out to \"${out}\"")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(out "")
|
||||||
|
string(APPEND out a)
|
||||||
|
if(NOT out STREQUAL "a")
|
||||||
|
message(FATAL_ERROR "\"string(APPEND out a)\" set out to \"${out}\"")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(out x)
|
||||||
|
string(APPEND out a)
|
||||||
|
if(NOT out STREQUAL "xa")
|
||||||
|
message(FATAL_ERROR "\"string(APPEND out a)\" set out to \"${out}\"")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
set(out x)
|
||||||
|
string(APPEND out a "b")
|
||||||
|
if(NOT out STREQUAL "xab")
|
||||||
|
message(FATAL_ERROR "\"string(APPEND out a \"b\")\" set out to \"${out}\"")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(b)
|
||||||
|
set(out x)
|
||||||
|
string(APPEND out ${b})
|
||||||
|
if(NOT out STREQUAL "x")
|
||||||
|
message(FATAL_ERROR "\"string(APPEND out \${b})\" set out to \"${out}\"")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(b b)
|
||||||
|
set(out x)
|
||||||
|
string(APPEND out a "${b}" [[
|
||||||
|
${c}]])
|
||||||
|
if(NOT out STREQUAL "xab\${c}")
|
||||||
|
message(FATAL_ERROR "\"string(APPEND out a \"\${b}\" [[\${c}]])\" set out to \"${out}\"")
|
||||||
|
endif()
|
1
Tests/RunCMake/string/AppendNoArgs-result.txt
Normal file
1
Tests/RunCMake/string/AppendNoArgs-result.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
1
|
4
Tests/RunCMake/string/AppendNoArgs-stderr.txt
Normal file
4
Tests/RunCMake/string/AppendNoArgs-stderr.txt
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
CMake Error at AppendNoArgs.cmake:1 \(string\):
|
||||||
|
string sub-command APPEND requires at least one argument.
|
||||||
|
Call Stack \(most recent call first\):
|
||||||
|
CMakeLists.txt:3 \(include\)
|
1
Tests/RunCMake/string/AppendNoArgs.cmake
Normal file
1
Tests/RunCMake/string/AppendNoArgs.cmake
Normal file
@ -0,0 +1 @@
|
|||||||
|
string(APPEND)
|
@ -1,5 +1,8 @@
|
|||||||
include(RunCMake)
|
include(RunCMake)
|
||||||
|
|
||||||
|
run_cmake(Append)
|
||||||
|
run_cmake(AppendNoArgs)
|
||||||
|
|
||||||
run_cmake(Concat)
|
run_cmake(Concat)
|
||||||
run_cmake(ConcatNoArgs)
|
run_cmake(ConcatNoArgs)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user