aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Interpreter/OptionValueString.cpp
diff options
context:
space:
mode:
authorEnrico Granata <egranata@apple.com>2012-12-11 22:42:19 +0000
committerEnrico Granata <egranata@apple.com>2012-12-11 22:42:19 +0000
commit9d14084b45320a1b4ff75eec7ede88b15ac3389c (patch)
tree0ee1659d40003336d7b4228117abd670039f5292 /lldb/source/Interpreter/OptionValueString.cpp
parent496970f6eec7697dbda6d02fc4f8dc595a24145f (diff)
downloadllvm-9d14084b45320a1b4ff75eec7ede88b15ac3389c.zip
llvm-9d14084b45320a1b4ff75eec7ede88b15ac3389c.tar.gz
llvm-9d14084b45320a1b4ff75eec7ede88b15ac3389c.tar.bz2
Adding a validation callback mechanism to OptionValueString (such a feature might theoretically be added to the general OptionValue base class should the need arise)
Using this mechanism, making sure that the options to pass a summary string or a named summary to frame variable do not have invalid values <rdar://problem/11576143> llvm-svn: 169927
Diffstat (limited to 'lldb/source/Interpreter/OptionValueString.cpp')
-rw-r--r--lldb/source/Interpreter/OptionValueString.cpp62
1 files changed, 60 insertions, 2 deletions
diff --git a/lldb/source/Interpreter/OptionValueString.cpp b/lldb/source/Interpreter/OptionValueString.cpp
index 696e62b7..91a9803 100644
--- a/lldb/source/Interpreter/OptionValueString.cpp
+++ b/lldb/source/Interpreter/OptionValueString.cpp
@@ -61,20 +61,36 @@ OptionValueString::SetValueFromCString (const char *value_cstr,
case eVarSetOperationInsertBefore:
case eVarSetOperationInsertAfter:
case eVarSetOperationRemove:
+ if (m_validator)
+ {
+ error = m_validator(value_cstr,m_validator_baton);
+ if (error.Fail())
+ return error;
+ }
error = OptionValue::SetValueFromCString (value_cstr, op);
break;
case eVarSetOperationAppend:
+ {
+ std::string new_value(m_current_value);
if (value_cstr && value_cstr[0])
{
if (m_options.Test (eOptionEncodeCharacterEscapeSequences))
{
std::string str;
Args::EncodeEscapeSequences (value_cstr, str);
- m_current_value += str;
+ new_value.append(str);
}
else
- m_current_value += value_cstr;
+ new_value.append(value_cstr);
+ }
+ if (m_validator)
+ {
+ error = m_validator(new_value.c_str(),m_validator_baton);
+ if (error.Fail())
+ return error;
+ }
+ m_current_value.assign(new_value);
}
break;
@@ -84,6 +100,12 @@ OptionValueString::SetValueFromCString (const char *value_cstr,
case eVarSetOperationReplace:
case eVarSetOperationAssign:
+ if (m_validator)
+ {
+ error = m_validator(value_cstr,m_validator_baton);
+ if (error.Fail())
+ return error;
+ }
m_value_was_set = true;
if (m_options.Test (eOptionEncodeCharacterEscapeSequences))
{
@@ -104,3 +126,39 @@ OptionValueString::DeepCopy () const
{
return OptionValueSP(new OptionValueString(*this));
}
+
+Error
+OptionValueString::SetCurrentValue (const char *value)
+{
+ if (m_validator)
+ {
+ Error error(m_validator(value,m_validator_baton));
+ if (error.Fail())
+ return error;
+ }
+ if (value && value[0])
+ m_current_value.assign (value);
+ else
+ m_current_value.clear();
+ return Error();
+}
+
+Error
+OptionValueString::AppendToCurrentValue (const char *value)
+{
+ if (value && value[0])
+ {
+ if (m_validator)
+ {
+ std::string new_value(m_current_value);
+ new_value.append(value);
+ Error error(m_validator(value,m_validator_baton));
+ if (error.Fail())
+ return error;
+ m_current_value.assign(new_value);
+ }
+ else
+ m_current_value.append (value);
+ }
+ return Error();
+}