Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
CMake
CMake
Commits
d66aa226
Commit
d66aa226
authored
Dec 04, 2002
by
Brad King
Browse files
ENH: Added COMPARE modes to STRING command.
parent
9992fe51
Changes
2
Hide whitespace changes
Inline
Side-by-side
Source/cmStringCommand.cxx
View file @
d66aa226
...
...
@@ -30,6 +30,10 @@ bool cmStringCommand::InitialPass(std::vector<std::string> const& args)
{
return
this
->
HandleRegexCommand
(
args
);
}
else
if
(
subCommand
==
"COMPARE"
)
{
return
this
->
HandleCompareCommand
(
args
);
}
std
::
string
e
=
"does not recognize sub-command "
+
subCommand
;
this
->
SetError
(
e
.
c_str
());
...
...
@@ -307,3 +311,59 @@ bool cmStringCommand::RegexReplace(std::vector<std::string> const& args)
m_Makefile
->
AddDefinition
(
outvar
.
c_str
(),
output
.
c_str
());
return
true
;
}
//----------------------------------------------------------------------------
bool
cmStringCommand
::
HandleCompareCommand
(
std
::
vector
<
std
::
string
>
const
&
args
)
{
if
(
args
.
size
()
<
2
)
{
this
->
SetError
(
"sub-command COMPARE requires a mode to be specified."
);
return
false
;
}
std
::
string
mode
=
args
[
1
];
if
((
mode
==
"EQUAL"
)
||
(
mode
==
"NOTEQUAL"
)
||
(
mode
==
"LESS"
)
||
(
mode
==
"GREATER"
))
{
if
(
args
.
size
()
<
5
)
{
std
::
string
e
=
"sub-command COMPARE, mode "
;
e
+=
mode
;
e
+=
" needs at least 5 arguments total to command."
;
this
->
SetError
(
e
.
c_str
());
return
false
;
}
const
std
::
string
&
left
=
args
[
2
];
const
std
::
string
&
right
=
args
[
3
];
const
std
::
string
&
outvar
=
args
[
4
];
bool
result
;
if
(
mode
==
"LESS"
)
{
result
=
(
left
<
right
);
}
else
if
(
mode
==
"GREATER"
)
{
result
=
(
left
>
right
);
}
else
if
(
mode
==
"EQUAL"
)
{
result
=
(
left
==
right
);
}
else
// if(mode == "NOTEQUAL")
{
result
=
!
(
left
==
right
);
}
if
(
result
)
{
m_Makefile
->
AddDefinition
(
outvar
.
c_str
(),
"1"
);
}
else
{
m_Makefile
->
AddDefinition
(
outvar
.
c_str
(),
"0"
);
}
return
true
;
}
std
::
string
e
=
"sub-command COMPARE does not recognize mode "
+
mode
;
this
->
SetError
(
e
.
c_str
());
return
false
;
}
Source/cmStringCommand.h
View file @
d66aa226
...
...
@@ -63,11 +63,16 @@ public:
"STRING(REGEX MATCH <regular_expression> <output variable> <input> [<input>...])
\n
"
"STRING(REGEX MATCHALL <regular_expression> <output variable> <input> [<input>...])
\n
"
"STRING(REGEX REPLACE <regular_expression> <replace_expression> <output variable> <input> [<input>...])
\n
"
"STRING(COMPARE EQUAL <string1> <string2> <output variable>)
\n
"
"STRING(COMPARE NOTEQUAL <string1> <string2> <output variable>)
\n
"
"STRING(COMPARE LESS <string1> <string2> <output variable>)
\n
"
"STRING(COMPARE GREATER <string1> <string2> <output variable>)
\n
"
"REGEX MATCH will match the regular expression once and store the match in the output variable.
\n
"
"REGEX MATCHALL will match the regular expression as many times as possible and store the matches
\n
"
" in the output variable as a list.
\n
"
"REGEX REPLACE will match the regular expression as many times as possible and substitute the
\n
"
" replacement expression for the match in the output.
\n
"
;
" replacement expression for the match in the output.
\n
"
"COMPARE EQUAL/NOTEQUAL/LESS/GREATER will compare the strings and store true or false in the output variable.
\n
"
;
}
cmTypeMacro
(
cmStringCommand
,
cmCommand
);
...
...
@@ -76,6 +81,7 @@ protected:
bool
RegexMatch
(
std
::
vector
<
std
::
string
>
const
&
args
);
bool
RegexMatchAll
(
std
::
vector
<
std
::
string
>
const
&
args
);
bool
RegexReplace
(
std
::
vector
<
std
::
string
>
const
&
args
);
bool
HandleCompareCommand
(
std
::
vector
<
std
::
string
>
const
&
args
);
class
RegexReplacement
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment