From 5b734e4c64b717fe6e214477d0e1faf8d2dc38fa Mon Sep 17 00:00:00 2001 From: Jacob Dufault Date: Thu, 30 Mar 2017 21:15:42 -0700 Subject: [PATCH] code dedup --- src/code_completion.cc | 6 ------ src/compilation_database_loader.cc | 14 -------------- src/utils.cc | 13 +++++++++++++ src/utils.h | 4 ++++ 4 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/code_completion.cc b/src/code_completion.cc index 7f2cc799..932403fc 100644 --- a/src/code_completion.cc +++ b/src/code_completion.cc @@ -26,12 +26,6 @@ unsigned Flags() { CXTranslationUnit_DetailedPreprocessingRecord; } -bool StartsWith(const std::string& value, const std::string& start) { - if (start.size() > value.size()) - return false; - return std::equal(start.begin(), start.end(), value.begin()); -} - lsCompletionItemKind GetCompletionKind(CXCursorKind cursor_kind) { switch (cursor_kind) { diff --git a/src/compilation_database_loader.cc b/src/compilation_database_loader.cc index aec319a0..6ad16d9a 100644 --- a/src/compilation_database_loader.cc +++ b/src/compilation_database_loader.cc @@ -8,20 +8,6 @@ #include - -// See http://stackoverflow.com/a/2072890 -bool EndsWith(const std::string& value, const std::string& ending) { - if (ending.size() > value.size()) - return false; - return std::equal(ending.rbegin(), ending.rend(), value.rbegin()); -} - -bool StartsWith(const std::string& value, const std::string& start) { - if (start.size() > value.size()) - return false; - return std::equal(start.begin(), start.end(), value.begin()); -} - std::vector LoadFromDirectoryListing(const std::string& project_directory) { std::vector result; diff --git a/src/utils.cc b/src/utils.cc index bd9b90d8..891cb5e6 100644 --- a/src/utils.cc +++ b/src/utils.cc @@ -6,6 +6,19 @@ #include +// See http://stackoverflow.com/a/2072890 +bool EndsWith(const std::string& value, const std::string& ending) { + if (ending.size() > value.size()) + return false; + return std::equal(ending.rbegin(), ending.rend(), value.rbegin()); +} + +bool StartsWith(const std::string& value, const std::string& start) { + if (start.size() > value.size()) + return false; + return std::equal(start.begin(), start.end(), value.begin()); +} + static std::vector GetFilesInFolderHelper(std::string folder, bool recursive, std::string output_prefix) { std::vector result; diff --git a/src/utils.h b/src/utils.h index ce07bd70..4e12caac 100644 --- a/src/utils.h +++ b/src/utils.h @@ -5,6 +5,10 @@ #include #include +// Returns true if |value| starts/ends with |start| or |ending|. +bool StartsWith(const std::string& value, const std::string& start); +bool EndsWith(const std::string& value, const std::string& ending); + // Finds all files in the given folder. This is recursive. std::vector GetFilesInFolder(std::string folder, bool recursive, bool add_folder_to_path); std::vector ReadLines(std::string filename);