From 2cf25b7c358e791d67ca37fd3d1321be2cc206ed Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 13 Dec 2009 16:59:28 -0500 Subject: [PATCH] Code Cleanup - Used the shorter form of std::string::substr that defaults the second argument to std::string::npos. --- src/Cmd.cpp | 2 +- src/Color.cpp | 6 +++--- src/Config.cpp | 2 +- src/Context.cpp | 14 +++++++------- src/Date.cpp | 4 ++-- src/Duration.cpp | 2 +- src/Nibbler.cpp | 8 ++++---- src/TDB.cpp | 8 ++++---- src/Task.cpp | 4 ++-- src/edit.cpp | 4 ++-- src/import.cpp | 6 ++---- src/report.cpp | 2 +- src/rules.cpp | 6 +++--- src/text.cpp | 16 ++++++++-------- 14 files changed, 41 insertions(+), 43 deletions(-) diff --git a/src/Cmd.cpp b/src/Cmd.cpp index fab2d0b83..05d5d78f7 100644 --- a/src/Cmd.cpp +++ b/src/Cmd.cpp @@ -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) { diff --git a/src/Color.cpp b/src/Color.cpp index 218306c4e..af9b5a9ef 100644 --- a/src/Color.cpp +++ b/src/Color.cpp @@ -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."; diff --git a/src/Config.cpp b/src/Config.cpp index 9da819406..7ae8d4bc7 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -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)) diff --git a/src/Context.cpp b/src/Context.cpp index 7f9c2cbcb..4a3902193 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -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] diff --git a/src/Date.cpp b/src/Date.cpp index ba6294952..8ad773791 100644 --- a/src/Date.cpp +++ b/src/Date.cpp @@ -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. diff --git a/src/Duration.cpp b/src/Duration.cpp index d554d8373..91136ba6a 100644 --- a/src/Duration.cpp +++ b/src/Duration.cpp @@ -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 diff --git a/src/Nibbler.cpp b/src/Nibbler.cpp index b48694f80..bd293b498 100644 --- a/src/Nibbler.cpp +++ b/src/Nibbler.cpp @@ -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; } diff --git a/src/TDB.cpp b/src/TDB.cpp index aad0f8727..1688646d6 100644 --- a/src/TDB.cpp +++ b/src/TDB.cpp @@ -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 (); } diff --git a/src/Task.cpp b/src/Task.cpp index 2f49c6ab1..7cd100a9a 100644 --- a/src/Task.cpp +++ b/src/Task.cpp @@ -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 diff --git a/src/edit.cpp b/src/edit.cpp index f8219e46d..46d6a196b 100644 --- a/src/edit.cpp +++ b/src/edit.cpp @@ -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)); } } diff --git a/src/import.cpp b/src/import.cpp index 2ad65c948..8d1cc4065 100644 --- a/src/import.cpp +++ b/src/import.cpp @@ -736,8 +736,7 @@ static std::string importTodoSh_2_0 (const std::vector & 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 & 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". diff --git a/src/report.cpp b/src/report.cpp index 25bd79e37..6d3a2ab27 100644 --- a/src/report.cpp +++ b/src/report.cpp @@ -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 (); } diff --git a/src/rules.cpp b/src/rules.cpp index 44b484574..e2f0dd018 100644 --- a/src/rules.cpp +++ b/src/rules.cpp @@ -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); diff --git a/src/text.cpp b/src/text.cpp index faebda956..48b38f88b 100644 --- a/src/text.cpp +++ b/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); } } }