Commit c66d232c authored by Brad King's avatar Brad King Committed by Kitware Robot
Browse files

Merge topic 'string-append'

2b18cdca string: add APPEND subcommand
parents 0d457c31 2b18cdca
......@@ -15,6 +15,7 @@ String operations.
string(REPLACE <match_string>
<replace_string> <output variable>
<input> [<input>...])
string(APPEND <string variable> [<input>...])
string(CONCAT <output variable> [<input>...])
string(<MD5|SHA1|SHA224|SHA256|SHA384|SHA512>
<output variable> <input>)
......@@ -55,6 +56,8 @@ through argument parsing.
``REPLACE`` will replace all occurrences of ``match_string`` in the input
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
the result in the named output variable.
......
string-append
-------------
* The :command:`string` command learned a new ``APPEND`` subcommand.
......@@ -74,6 +74,10 @@ bool cmStringCommand
{
return this->HandleLengthCommand(args);
}
else if(subCommand == "APPEND")
{
return this->HandleAppendCommand(args);
}
else if(subCommand == "CONCAT")
{
return this->HandleConcatCommand(args);
......@@ -729,6 +733,34 @@ bool cmStringCommand
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
::HandleConcatCommand(std::vector<std::string> const& args)
......
......@@ -67,6 +67,7 @@ protected:
bool HandleReplaceCommand(std::vector<std::string> const& args);
bool HandleLengthCommand(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 HandleStripCommand(std::vector<std::string> const& args);
bool HandleRandomCommand(std::vector<std::string> const& args);
......
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()
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\)
include(RunCMake)
run_cmake(Append)
run_cmake(AppendNoArgs)
run_cmake(Concat)
run_cmake(ConcatNoArgs)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment