Code Cleanup

- Used the shorter form of std::string::substr that defaults the second
  argument to std::string::npos.
This commit is contained in:
Paul Beckingham 2009-12-13 16:59:28 -05:00
parent 75e738a9c9
commit 2cf25b7c35
14 changed files with 41 additions and 43 deletions

View file

@ -147,7 +147,7 @@ void Cmd::load ()
{ {
if (i->substr (0, 7) == "report.") 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"); std::string::size_type columns = report.find (".columns");
if (columns != std::string::npos) if (columns != std::string::npos)
{ {

View file

@ -137,7 +137,7 @@ Color::Color (const std::string& spec)
else if (word.substr (0, 4) == "grey" || else if (word.substr (0, 4) == "grey" ||
word.substr (0, 4) == "gray") 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) if (index < 0 || index > 23)
throw std::string ("The color '") + *it + "' is not recognized."; 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. // rgbRGB, where 0 <= R,G,B <= 5.
else if (word.substr (0, 3) == "rgb") 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 || if (word.length () != 6 ||
index < 0 || index > 555) index < 0 || index > 555)
throw std::string ("The color '") + *it + "' is not recognized."; throw std::string ("The color '") + *it + "' is not recognized.";
@ -194,7 +194,7 @@ Color::Color (const std::string& spec)
// colorN, where 0 <= N <= 255. // colorN, where 0 <= N <= 255.
else if (word.substr (0, 5) == "color") 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) if (index < 0 || index > 255)
throw std::string ("The color '") + *it + "' is not recognized."; throw std::string ("The color '") + *it + "' is not recognized.";

View file

@ -99,7 +99,7 @@ bool Config::load (const std::string& file, int nest /* = 1 */)
std::string::size_type include = line.find ("include"); // no i18n. std::string::size_type include = line.find ("include"); // no i18n.
if (include != std::string::npos) 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 (isAbsolutePath (included))
{ {
if (!access (included.c_str (), F_OK | R_OK)) if (!access (included.c_str (), F_OK | R_OK))

View file

@ -362,7 +362,7 @@ void Context::loadCorrectConfigFile ()
else if (arg->substr (0, 3) == "rc:") else if (arg->substr (0, 3) == "rc:")
{ {
file_override = *arg; file_override = *arg;
rc = arg->substr (3, std::string::npos); rc = arg->substr (3);
home = rc; home = rc;
std::string::size_type last_slash = rc.rfind ("/"); std::string::size_type last_slash = rc.rfind ("/");
@ -393,7 +393,7 @@ void Context::loadCorrectConfigFile ()
else if (arg->substr (0, 17) == "rc.data.location:" || else if (arg->substr (0, 17) == "rc.data.location:" ||
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 header ("Using alternate data.location " + data); // TODO i18n
break; break;
} }
@ -448,7 +448,7 @@ void Context::loadCorrectConfigFile ()
config.set (name, value); config.set (name, value);
var_overrides += " " + *arg; var_overrides += " " + *arg;
footnote (std::string ("Configuration override ") + // TODO i18n footnote (std::string ("Configuration override ") + // TODO i18n
arg->substr (3, std::string::npos)); arg->substr (3));
} }
} }
else else
@ -469,7 +469,7 @@ void Context::loadAliases ()
{ {
if (var->substr (0, 6) == "alias.") 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); std::string canonical = config.get (*var);
aliases[alias] = canonical; aliases[alias] = canonical;
@ -538,8 +538,8 @@ void Context::parse (
throw stringtable.get (TAGS_NO_COMMA, throw stringtable.get (TAGS_NO_COMMA,
"Tags are not permitted to contain commas."); "Tags are not permitted to contain commas.");
tagAdditions.push_back (arg->substr (1, std::string::npos)); tagAdditions.push_back (arg->substr (1));
parseTask.addTag (arg->substr (1, std::string::npos)); parseTask.addTag (arg->substr (1));
} }
// Tags to remove begin with '-'. // Tags to remove begin with '-'.
@ -555,7 +555,7 @@ void Context::parse (
throw stringtable.get (TAGS_NO_COMMA, throw stringtable.get (TAGS_NO_COMMA,
"Tags are not permitted to contain commas."); "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] // Atributes - name[.mod]:[value]

View file

@ -705,12 +705,12 @@ bool Date::isRelativeDate (const std::string& input)
if (isdigit (input[1])) if (isdigit (input[1]))
{ {
number = atoi (input.substr (0, 2).c_str ()); number = atoi (input.substr (0, 2).c_str ());
ordinal = lowerCase (input.substr (2, std::string::npos)); ordinal = lowerCase (input.substr (2));
} }
else else
{ {
number = atoi (input.substr (0, 2).c_str ()); number = atoi (input.substr (0, 2).c_str ());
ordinal = lowerCase (input.substr (1, std::string::npos)); ordinal = lowerCase (input.substr (1));
} }
// Sanity check. // Sanity check.

View file

@ -116,7 +116,7 @@ bool Duration::valid (const std::string& input) const
if (! isdigit (lower_input[i]) && if (! isdigit (lower_input[i]) &&
i == length - 1) 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 if (type == "d" || // TODO i18n
type == "w" || // TODO i18n type == "w" || // TODO i18n
type == "m" || // TODO i18n type == "m" || // TODO i18n

View file

@ -88,7 +88,7 @@ bool Nibbler::getUntil (char c, std::string& result)
} }
else else
{ {
result = mInput.substr (mCursor, std::string::npos); result = mInput.substr (mCursor);
mCursor = mInput.length (); mCursor = mInput.length ();
} }
@ -111,7 +111,7 @@ bool Nibbler::getUntil (const std::string& terminator, std::string& result)
} }
else else
{ {
result = mInput.substr (mCursor, std::string::npos); result = mInput.substr (mCursor);
mCursor = mInput.length (); mCursor = mInput.length ();
} }
@ -134,7 +134,7 @@ bool Nibbler::getUntilOneOf (const std::string& chars, std::string& result)
} }
else else
{ {
result = mInput.substr (mCursor, std::string::npos); result = mInput.substr (mCursor);
mCursor = mInput.length (); mCursor = mInput.length ();
} }
@ -284,7 +284,7 @@ bool Nibbler::getUntilEOS (std::string& result)
{ {
if (mCursor < mInput.length ()) if (mCursor < mInput.length ())
{ {
result = mInput.substr (mCursor, std::string::npos); result = mInput.substr (mCursor);
mCursor = mInput.length (); mCursor = mInput.length ();
return true; return true;
} }

View file

@ -519,22 +519,22 @@ void TDB::undo ()
// pop last tx // pop last tx
u.pop_back (); // separator. u.pop_back (); // separator.
std::string current = u.back ().substr (4, std::string::npos); std::string current = u.back ().substr (4);
u.pop_back (); u.pop_back ();
std::string prior; std::string prior;
std::string when; std::string when;
if (u.back ().substr (0, 5) == "time ") if (u.back ().substr (0, 5) == "time ")
{ {
when = u.back ().substr (5, std::string::npos); when = u.back ().substr (5);
u.pop_back (); u.pop_back ();
prior = ""; prior = "";
} }
else else
{ {
prior = u.back ().substr (4, std::string::npos); prior = u.back ().substr (4);
u.pop_back (); u.pop_back ();
when = u.back ().substr (5, std::string::npos); when = u.back ().substr (5);
u.pop_back (); u.pop_back ();
} }

View file

@ -220,7 +220,7 @@ void Task::legacyParse (const std::string& line)
set (pair[0], pair[1]); 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 else
throw std::string ("Missing attribute brackets"); // TODO i18n 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 else
throw std::string ("Missing annotation brackets."); // TODO i18n throw std::string ("Missing annotation brackets."); // TODO i18n

View file

@ -161,7 +161,7 @@ static std::string formatTask (Task task)
task.getAnnotations (annotations); task.getAnnotations (annotations);
foreach (anno, 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")) before << " Annotation: " << dt.toString (context.config.get ("dateformat", "m/d/Y"))
<< " " << anno->value () << std::endl; << " " << anno->value () << std::endl;
} }
@ -508,7 +508,7 @@ static void parseTask (Task& task, const std::string& after)
std::stringstream name; std::stringstream name;
name << "annotation_" << when.toEpoch (); 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)); annotations.push_back (Att (name.str (), text));
} }
} }

View file

@ -736,8 +736,7 @@ static std::string importTodoSh_2_0 (const std::vector <std::string>& lines)
if (words[w].length () > 1 && if (words[w].length () > 1 &&
words[w][0] == '+') words[w][0] == '+')
{ {
context.args.push_back (std::string ("project:") + context.args.push_back (std::string ("project:") + words[w].substr (1));
words[w].substr (1, std::string::npos));
} }
// Convert "+aaa" to "project:aaa". // 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 && else if (words[w].length () > 1 &&
words[w][0] == '@') words[w][0] == '@')
{ {
context.args.push_back (std::string ("+") + context.args.push_back (std::string ("+") + words[w].substr (1));
words[w].substr (1, std::string::npos));
} }
// Convert "(A)" to "priority:H". // Convert "(A)" to "priority:H".

View file

@ -2059,7 +2059,7 @@ std::string getFullDescription (Task& task)
task.getAnnotations (annotations); task.getAnnotations (annotations);
foreach (anno, 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")); std::string when = dt.toString (context.config.get ("dateformat", "m/d/Y"));
desc += "\n" + when + " " + anno->value (); desc += "\n" + when + " " + anno->value ();
} }

View file

@ -98,7 +98,7 @@ void autoColorize (Task& task, Color& c)
{ {
if (it->first.substr (0, 10) == "color.tag.") 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)) if (task.hasTag (value))
c.blend (it->second); c.blend (it->second);
} }
@ -109,7 +109,7 @@ void autoColorize (Task& task, Color& c)
{ {
if (it->first.substr (0, 14) == "color.project.") 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) if (task.get ("project") == value)
c.blend (it->second); c.blend (it->second);
} }
@ -120,7 +120,7 @@ void autoColorize (Task& task, Color& c)
{ {
if (it->first.substr (0, 14) == "color.keyword.") 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")); std::string desc = lowerCase (task.get ("description"));
if (desc.find (value) != std::string::npos) if (desc.find (value) != std::string::npos)
c.blend (it->second); c.blend (it->second);

View file

@ -69,7 +69,7 @@ void split (
} }
if (input.length ()) 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 ()) 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 ()) 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 ()) 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) if (eol != std::string::npos && eol < (unsigned) length)
{ {
line = text.substr (0, eol); // strip \n line = text.substr (0, eol); // strip \n
text = text.substr (eol + 1, std::string::npos); text = text.substr (eol + 1);
return; return;
} }
@ -222,7 +222,7 @@ void extractLine (std::string& text, std::string& line, int length)
if (eol) if (eol)
{ {
line = text.substr (0, 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. // If no space was found, hyphenate.
@ -231,12 +231,12 @@ void extractLine (std::string& text, std::string& line, int length)
if (length > 1) if (length > 1)
{ {
line = text.substr (0, length - 1) + "-"; line = text.substr (0, length - 1) + "-";
text = text.substr (length - 1, std::string::npos); text = text.substr (length - 1);
} }
else else
{ {
line = text.substr (0, 1); line = text.substr (0, 1);
text = text.substr (length, std::string::npos); text = text.substr (length);
} }
} }
} }