Integration - mod

- Now handles blank modifiers.  Like it should.
This commit is contained in:
Paul Beckingham
2009-06-13 17:56:48 -04:00
parent 25d27bec93
commit a04bfc468b
2 changed files with 86 additions and 44 deletions

View File

@@ -215,7 +215,8 @@ bool Att::validNameValue (
std::string writableMod = mod; std::string writableMod = mod;
std::string writableValue = value; std::string writableValue = value;
bool status = Att::validNameValue (writableName, writableMod, writableValue); bool status = Att::validNameValue (writableName, writableMod, writableValue);
/*
// TODO Is this even worth doing?
if (name != writableName) if (name != writableName)
throw std::string ("The attribute '") + name + "' was not fully qualified."; throw std::string ("The attribute '") + name + "' was not fully qualified.";
@@ -224,7 +225,7 @@ bool Att::validNameValue (
if (value != writableValue) if (value != writableValue)
throw std::string ("The value '") + value + "' was not fully qualified."; throw std::string ("The value '") + value + "' was not fully qualified.";
*/
return status; return status;
} }
@@ -262,61 +263,89 @@ bool Att::validNameValue (
name = matches[0]; name = matches[0];
// Second, guess at the modifier name. // Second, guess at the modifier name.
candidates.clear (); if (mod != "")
for (unsigned i = 0; i < NUM_MODIFIER_NAMES; ++i)
candidates.push_back (modifierNames[i]);
matches.clear ();
autoComplete (mod, candidates, matches);
if (matches.size () == 0)
throw std::string ("Unrecognized modifier '") + name + "'";
else if (matches.size () != 1)
{ {
std::string error = "Ambiguous modifier '" + name + "' - could be either of "; // TODO i18n candidates.clear ();
for (unsigned i = 0; i < NUM_MODIFIER_NAMES; ++i)
candidates.push_back (modifierNames[i]);
std::string combined; matches.clear ();
join (combined, ", ", matches); autoComplete (mod, candidates, matches);
error += combined;
throw error + combined; if (matches.size () == 0)
throw std::string ("Unrecognized modifier '") + mod + "'";
else if (matches.size () != 1)
{
std::string error = "Ambiguous modifier '" + mod + "' - could be either of "; // TODO i18n
std::string combined;
join (combined, ", ", matches);
error += combined;
throw error + combined;
}
mod = matches[0];
} }
mod = matches[0];
// Thirdly, make sure the value has the expected form or values. // Thirdly, make sure the value has the expected form or values.
if (name == "project" && !noSpaces (value)) if (name == "project")
throw std::string ("The '") + name + "' attribute may not contain spaces.";
else if (name == "priority" && value != "")
{ {
value = upperCase (value); if (!noSpaces (value))
if (value != "H" && throw std::string ("The '") + name + "' attribute may not contain spaces.";
value != "M" &&
value != "L")
throw std::string ("\"") +
value +
"\" is not a valid priority. Use H, M, L or leave blank.";
} }
else if (name == "description" && (value != "" || !noVerticalSpace (value))) else if (name == "priority")
throw std::string ("The '") + name + "' attribute must not be blank, and must not contain vertical white space."; {
if (value != "")
{
value = upperCase (value);
if (value != "H" &&
value != "M" &&
value != "L")
throw std::string ("\"") +
value +
"\" is not a valid priority. Use H, M, L or leave blank.";
}
}
else if ((name == "fg" || name == "bg") && value != "") else if (name == "description")
Text::guessColor (value); {
if (value != "" || !noVerticalSpace (value))
throw std::string ("The '") + name + "' attribute must not be blank, and must not contain vertical white space.";
}
else if (name == "due" && value != "") else if (name == "fg" || name == "bg")
Date (value); {
if (value != "")
Text::guessColor (value);
}
else if (name == "until" && value != "") else if (name == "due")
Date (value); {
if (value != "")
Date (value);
}
else if (name == "recur" && value != "") else if (name == "until")
Duration (value); {
if (value != "")
Date (value);
}
else if (name == "limit" && (value == "" || !digitsOnly (value))) else if (name == "recur")
throw std::string ("The '") + name + "' attribute must be an integer."; {
if (value != "")
Duration (value);
}
// TODO Not ready for prime time.
else if (name == "limit")
{
if (value == "" || !digitsOnly (value))
throw std::string ("The '") + name + "' attribute must be an integer.";
}
// Some attributes are intended to be private. // Some attributes are intended to be private.
else if (name == "entry" || else if (name == "entry" ||
@@ -326,9 +355,11 @@ bool Att::validNameValue (
name == "imask" || name == "imask" ||
name == "uuid" || name == "uuid" ||
name == "status") name == "status")
{
throw std::string ("\"") + throw std::string ("\"") +
name + name +
"\" is not an attribute you may modify directly."; "\" is not an attribute you may modify directly.";
}
else else
throw std::string ("'") + name + "' is an unrecognized attribute."; throw std::string ("'") + name + "' is an unrecognized attribute.";
@@ -509,7 +540,7 @@ std::string Att::composeF4 () const
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void Att::mod (const std::string& input) void Att::mod (const std::string& input)
{ {
if (!validMod (input)) if (input != "" && !validMod (input))
throw std::string ("The name '") + input + "' is not a valid modifier"; // TODO i18n throw std::string ("The name '") + input + "' is not a valid modifier"; // TODO i18n
mMod = input; mMod = input;

View File

@@ -383,6 +383,7 @@ std::cout << "# parse tag removal '" << *arg << "'" << std::endl;
tagRemovals.push_back (arg->substr (1, std::string::npos)); tagRemovals.push_back (arg->substr (1, std::string::npos));
} }
// Atributes - name[.mod]:[value]
else if (attribute.valid (*arg)) else if (attribute.valid (*arg))
{ {
std::cout << "# parse attribute '" << *arg << "'" << std::endl; std::cout << "# parse attribute '" << *arg << "'" << std::endl;
@@ -390,6 +391,16 @@ std::cout << "# parse attribute '" << *arg << "'" << std::endl;
foundSomethingAfterSequence = true; foundSomethingAfterSequence = true;
attribute.parse (*arg); attribute.parse (*arg);
// There has to be a better way. And it starts with a fresh coffee.
std::string name = attribute.name ();
std::string mod = attribute.mod ();
std::string value = attribute.value ();
attribute.validNameValue (name, mod, value);
attribute.name (name);
attribute.mod (mod);
attribute.value (value);
task[attribute.name ()] = attribute; task[attribute.name ()] = attribute;
} }