mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Code Cleanup
- Used the shorter form of std::string::substr that defaults the second argument to std::string::npos.
This commit is contained in:
parent
75e738a9c9
commit
2cf25b7c35
14 changed files with 41 additions and 43 deletions
|
@ -147,7 +147,7 @@ void Cmd::load ()
|
|||
{
|
||||
if (i->substr (0, 7) == "report.")
|
||||
{
|
||||
std::string report = i->substr (7, std::string::npos);
|
||||
std::string report = i->substr (7);
|
||||
std::string::size_type columns = report.find (".columns");
|
||||
if (columns != std::string::npos)
|
||||
{
|
||||
|
|
|
@ -137,7 +137,7 @@ Color::Color (const std::string& spec)
|
|||
else if (word.substr (0, 4) == "grey" ||
|
||||
word.substr (0, 4) == "gray")
|
||||
{
|
||||
index = atoi (word.substr (4, std::string::npos).c_str ());
|
||||
index = atoi (word.substr (4).c_str ());
|
||||
if (index < 0 || index > 23)
|
||||
throw std::string ("The color '") + *it + "' is not recognized.";
|
||||
|
||||
|
@ -160,7 +160,7 @@ Color::Color (const std::string& spec)
|
|||
// rgbRGB, where 0 <= R,G,B <= 5.
|
||||
else if (word.substr (0, 3) == "rgb")
|
||||
{
|
||||
index = atoi (word.substr (3, std::string::npos).c_str ());
|
||||
index = atoi (word.substr (3).c_str ());
|
||||
if (word.length () != 6 ||
|
||||
index < 0 || index > 555)
|
||||
throw std::string ("The color '") + *it + "' is not recognized.";
|
||||
|
@ -194,7 +194,7 @@ Color::Color (const std::string& spec)
|
|||
// colorN, where 0 <= N <= 255.
|
||||
else if (word.substr (0, 5) == "color")
|
||||
{
|
||||
index = atoi (word.substr (5, std::string::npos).c_str ());
|
||||
index = atoi (word.substr (5).c_str ());
|
||||
if (index < 0 || index > 255)
|
||||
throw std::string ("The color '") + *it + "' is not recognized.";
|
||||
|
||||
|
|
|
@ -99,7 +99,7 @@ bool Config::load (const std::string& file, int nest /* = 1 */)
|
|||
std::string::size_type include = line.find ("include"); // no i18n.
|
||||
if (include != std::string::npos)
|
||||
{
|
||||
std::string included = expandPath ( trim ( line.substr (include + 7, std::string::npos), " \t"));
|
||||
std::string included = expandPath ( trim ( line.substr (include + 7), " \t"));
|
||||
if (isAbsolutePath (included))
|
||||
{
|
||||
if (!access (included.c_str (), F_OK | R_OK))
|
||||
|
|
|
@ -362,7 +362,7 @@ void Context::loadCorrectConfigFile ()
|
|||
else if (arg->substr (0, 3) == "rc:")
|
||||
{
|
||||
file_override = *arg;
|
||||
rc = arg->substr (3, std::string::npos);
|
||||
rc = arg->substr (3);
|
||||
|
||||
home = rc;
|
||||
std::string::size_type last_slash = rc.rfind ("/");
|
||||
|
@ -393,7 +393,7 @@ void Context::loadCorrectConfigFile ()
|
|||
else if (arg->substr (0, 17) == "rc.data.location:" ||
|
||||
arg->substr (0, 17) == "rc.data.location=")
|
||||
{
|
||||
data = arg->substr (17, std::string::npos);
|
||||
data = arg->substr (17);
|
||||
header ("Using alternate data.location " + data); // TODO i18n
|
||||
break;
|
||||
}
|
||||
|
@ -448,7 +448,7 @@ void Context::loadCorrectConfigFile ()
|
|||
config.set (name, value);
|
||||
var_overrides += " " + *arg;
|
||||
footnote (std::string ("Configuration override ") + // TODO i18n
|
||||
arg->substr (3, std::string::npos));
|
||||
arg->substr (3));
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -469,7 +469,7 @@ void Context::loadAliases ()
|
|||
{
|
||||
if (var->substr (0, 6) == "alias.")
|
||||
{
|
||||
std::string alias = var->substr (6, std::string::npos);
|
||||
std::string alias = var->substr (6);
|
||||
std::string canonical = config.get (*var);
|
||||
|
||||
aliases[alias] = canonical;
|
||||
|
@ -538,8 +538,8 @@ void Context::parse (
|
|||
throw stringtable.get (TAGS_NO_COMMA,
|
||||
"Tags are not permitted to contain commas.");
|
||||
|
||||
tagAdditions.push_back (arg->substr (1, std::string::npos));
|
||||
parseTask.addTag (arg->substr (1, std::string::npos));
|
||||
tagAdditions.push_back (arg->substr (1));
|
||||
parseTask.addTag (arg->substr (1));
|
||||
}
|
||||
|
||||
// Tags to remove begin with '-'.
|
||||
|
@ -555,7 +555,7 @@ void Context::parse (
|
|||
throw stringtable.get (TAGS_NO_COMMA,
|
||||
"Tags are not permitted to contain commas.");
|
||||
|
||||
tagRemovals.push_back (arg->substr (1, std::string::npos));
|
||||
tagRemovals.push_back (arg->substr (1));
|
||||
}
|
||||
|
||||
// Atributes - name[.mod]:[value]
|
||||
|
|
|
@ -705,12 +705,12 @@ bool Date::isRelativeDate (const std::string& input)
|
|||
if (isdigit (input[1]))
|
||||
{
|
||||
number = atoi (input.substr (0, 2).c_str ());
|
||||
ordinal = lowerCase (input.substr (2, std::string::npos));
|
||||
ordinal = lowerCase (input.substr (2));
|
||||
}
|
||||
else
|
||||
{
|
||||
number = atoi (input.substr (0, 2).c_str ());
|
||||
ordinal = lowerCase (input.substr (1, std::string::npos));
|
||||
ordinal = lowerCase (input.substr (1));
|
||||
}
|
||||
|
||||
// Sanity check.
|
||||
|
|
|
@ -116,7 +116,7 @@ bool Duration::valid (const std::string& input) const
|
|||
if (! isdigit (lower_input[i]) &&
|
||||
i == length - 1)
|
||||
{
|
||||
std::string type = lower_input.substr (length - 1, std::string::npos);
|
||||
std::string type = lower_input.substr (length - 1);
|
||||
if (type == "d" || // TODO i18n
|
||||
type == "w" || // TODO i18n
|
||||
type == "m" || // TODO i18n
|
||||
|
|
|
@ -88,7 +88,7 @@ bool Nibbler::getUntil (char c, std::string& result)
|
|||
}
|
||||
else
|
||||
{
|
||||
result = mInput.substr (mCursor, std::string::npos);
|
||||
result = mInput.substr (mCursor);
|
||||
mCursor = mInput.length ();
|
||||
}
|
||||
|
||||
|
@ -111,7 +111,7 @@ bool Nibbler::getUntil (const std::string& terminator, std::string& result)
|
|||
}
|
||||
else
|
||||
{
|
||||
result = mInput.substr (mCursor, std::string::npos);
|
||||
result = mInput.substr (mCursor);
|
||||
mCursor = mInput.length ();
|
||||
}
|
||||
|
||||
|
@ -134,7 +134,7 @@ bool Nibbler::getUntilOneOf (const std::string& chars, std::string& result)
|
|||
}
|
||||
else
|
||||
{
|
||||
result = mInput.substr (mCursor, std::string::npos);
|
||||
result = mInput.substr (mCursor);
|
||||
mCursor = mInput.length ();
|
||||
}
|
||||
|
||||
|
@ -284,7 +284,7 @@ bool Nibbler::getUntilEOS (std::string& result)
|
|||
{
|
||||
if (mCursor < mInput.length ())
|
||||
{
|
||||
result = mInput.substr (mCursor, std::string::npos);
|
||||
result = mInput.substr (mCursor);
|
||||
mCursor = mInput.length ();
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -519,22 +519,22 @@ void TDB::undo ()
|
|||
// pop last tx
|
||||
u.pop_back (); // separator.
|
||||
|
||||
std::string current = u.back ().substr (4, std::string::npos);
|
||||
std::string current = u.back ().substr (4);
|
||||
u.pop_back ();
|
||||
|
||||
std::string prior;
|
||||
std::string when;
|
||||
if (u.back ().substr (0, 5) == "time ")
|
||||
{
|
||||
when = u.back ().substr (5, std::string::npos);
|
||||
when = u.back ().substr (5);
|
||||
u.pop_back ();
|
||||
prior = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
prior = u.back ().substr (4, std::string::npos);
|
||||
prior = u.back ().substr (4);
|
||||
u.pop_back ();
|
||||
when = u.back ().substr (5, std::string::npos);
|
||||
when = u.back ().substr (5);
|
||||
u.pop_back ();
|
||||
}
|
||||
|
||||
|
|
|
@ -220,7 +220,7 @@ void Task::legacyParse (const std::string& line)
|
|||
set (pair[0], pair[1]);
|
||||
}
|
||||
|
||||
set ("description", line.substr (closeAttrBracket + 2, std::string::npos)); // No i18n
|
||||
set ("description", line.substr (closeAttrBracket + 2)); // No i18n
|
||||
}
|
||||
else
|
||||
throw std::string ("Missing attribute brackets"); // TODO i18n
|
||||
|
@ -321,7 +321,7 @@ void Task::legacyParse (const std::string& line)
|
|||
}
|
||||
}
|
||||
|
||||
set ("description", line.substr (closeAnnoBracket + 2, std::string::npos)); // No i18n
|
||||
set ("description", line.substr (closeAnnoBracket + 2)); // No i18n
|
||||
}
|
||||
else
|
||||
throw std::string ("Missing annotation brackets."); // TODO i18n
|
||||
|
|
|
@ -161,7 +161,7 @@ static std::string formatTask (Task task)
|
|||
task.getAnnotations (annotations);
|
||||
foreach (anno, annotations)
|
||||
{
|
||||
Date dt (::atoi (anno->name ().substr (11, std::string::npos).c_str ()));
|
||||
Date dt (::atoi (anno->name ().substr (11).c_str ()));
|
||||
before << " Annotation: " << dt.toString (context.config.get ("dateformat", "m/d/Y"))
|
||||
<< " " << anno->value () << std::endl;
|
||||
}
|
||||
|
@ -508,7 +508,7 @@ static void parseTask (Task& task, const std::string& after)
|
|||
|
||||
std::stringstream name;
|
||||
name << "annotation_" << when.toEpoch ();
|
||||
std::string text = trim (value.substr (gap, std::string::npos), "\t ");
|
||||
std::string text = trim (value.substr (gap), "\t ");
|
||||
annotations.push_back (Att (name.str (), text));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -736,8 +736,7 @@ static std::string importTodoSh_2_0 (const std::vector <std::string>& lines)
|
|||
if (words[w].length () > 1 &&
|
||||
words[w][0] == '+')
|
||||
{
|
||||
context.args.push_back (std::string ("project:") +
|
||||
words[w].substr (1, std::string::npos));
|
||||
context.args.push_back (std::string ("project:") + words[w].substr (1));
|
||||
}
|
||||
|
||||
// Convert "+aaa" to "project:aaa".
|
||||
|
@ -745,8 +744,7 @@ static std::string importTodoSh_2_0 (const std::vector <std::string>& lines)
|
|||
else if (words[w].length () > 1 &&
|
||||
words[w][0] == '@')
|
||||
{
|
||||
context.args.push_back (std::string ("+") +
|
||||
words[w].substr (1, std::string::npos));
|
||||
context.args.push_back (std::string ("+") + words[w].substr (1));
|
||||
}
|
||||
|
||||
// Convert "(A)" to "priority:H".
|
||||
|
|
|
@ -2059,7 +2059,7 @@ std::string getFullDescription (Task& task)
|
|||
task.getAnnotations (annotations);
|
||||
foreach (anno, annotations)
|
||||
{
|
||||
Date dt (atoi (anno->name ().substr (11, std::string::npos).c_str ()));
|
||||
Date dt (atoi (anno->name ().substr (11).c_str ()));
|
||||
std::string when = dt.toString (context.config.get ("dateformat", "m/d/Y"));
|
||||
desc += "\n" + when + " " + anno->value ();
|
||||
}
|
||||
|
|
|
@ -98,7 +98,7 @@ void autoColorize (Task& task, Color& c)
|
|||
{
|
||||
if (it->first.substr (0, 10) == "color.tag.")
|
||||
{
|
||||
std::string value = it->first.substr (10, std::string::npos);
|
||||
std::string value = it->first.substr (10);
|
||||
if (task.hasTag (value))
|
||||
c.blend (it->second);
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ void autoColorize (Task& task, Color& c)
|
|||
{
|
||||
if (it->first.substr (0, 14) == "color.project.")
|
||||
{
|
||||
std::string value = it->first.substr (14, std::string::npos);
|
||||
std::string value = it->first.substr (14);
|
||||
if (task.get ("project") == value)
|
||||
c.blend (it->second);
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ void autoColorize (Task& task, Color& c)
|
|||
{
|
||||
if (it->first.substr (0, 14) == "color.keyword.")
|
||||
{
|
||||
std::string value = lowerCase (it->first.substr (14, std::string::npos));
|
||||
std::string value = lowerCase (it->first.substr (14));
|
||||
std::string desc = lowerCase (task.get ("description"));
|
||||
if (desc.find (value) != std::string::npos)
|
||||
c.blend (it->second);
|
||||
|
|
16
src/text.cpp
16
src/text.cpp
|
@ -69,7 +69,7 @@ void split (
|
|||
}
|
||||
|
||||
if (input.length ())
|
||||
results.push_back (input.substr (start, std::string::npos));
|
||||
results.push_back (input.substr (start));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -89,7 +89,7 @@ void split_minimal (
|
|||
}
|
||||
|
||||
if (input.length ())
|
||||
results.push_back (input.substr (start, std::string::npos));
|
||||
results.push_back (input.substr (start));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -110,7 +110,7 @@ void split (
|
|||
}
|
||||
|
||||
if (input.length ())
|
||||
results.push_back (input.substr (start, std::string::npos));
|
||||
results.push_back (input.substr (start));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -132,7 +132,7 @@ void split_minimal (
|
|||
}
|
||||
|
||||
if (input.length ())
|
||||
results.push_back (input.substr (start, std::string::npos));
|
||||
results.push_back (input.substr (start));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -198,7 +198,7 @@ void extractLine (std::string& text, std::string& line, int length)
|
|||
if (eol != std::string::npos && eol < (unsigned) length)
|
||||
{
|
||||
line = text.substr (0, eol); // strip \n
|
||||
text = text.substr (eol + 1, std::string::npos);
|
||||
text = text.substr (eol + 1);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -222,7 +222,7 @@ void extractLine (std::string& text, std::string& line, int length)
|
|||
if (eol)
|
||||
{
|
||||
line = text.substr (0, eol);
|
||||
text = text.substr (eol + 1, std::string::npos);
|
||||
text = text.substr (eol + 1);
|
||||
}
|
||||
|
||||
// If no space was found, hyphenate.
|
||||
|
@ -231,12 +231,12 @@ void extractLine (std::string& text, std::string& line, int length)
|
|||
if (length > 1)
|
||||
{
|
||||
line = text.substr (0, length - 1) + "-";
|
||||
text = text.substr (length - 1, std::string::npos);
|
||||
text = text.substr (length - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
line = text.substr (0, 1);
|
||||
text = text.substr (length, std::string::npos);
|
||||
text = text.substr (length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue