code dedup

This commit is contained in:
Jacob Dufault 2017-03-30 21:15:42 -07:00
parent 82596abc51
commit 5b734e4c64
4 changed files with 17 additions and 20 deletions

View File

@ -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) {

View File

@ -8,20 +8,6 @@
#include <iostream>
// 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<CompilationEntry> LoadFromDirectoryListing(const std::string& project_directory) {
std::vector<CompilationEntry> result;

View File

@ -6,6 +6,19 @@
#include <tinydir.h>
// 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<std::string> GetFilesInFolderHelper(std::string folder, bool recursive, std::string output_prefix) {
std::vector<std::string> result;

View File

@ -5,6 +5,10 @@
#include <vector>
#include <memory>
// 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<std::string> GetFilesInFolder(std::string folder, bool recursive, bool add_folder_to_path);
std::vector<std::string> ReadLines(std::string filename);