Replace CMAKE_INSTALL_PREFIX from default config if it hasn't been swapped out by CMAKE

This commit is contained in:
Matt Hill
2016-03-25 09:12:24 -04:00
parent 747acb6d96
commit 677dc4667d
3 changed files with 16 additions and 0 deletions

View File

@@ -167,6 +167,11 @@ namespace alpr
runtimeBaseDir = getString(ini,defaultIni, "", "runtime_dir", DEFAULT_RUNTIME_DATA_DIR);
// Special hack to allow config files to work if the package hasn't been installed
// Cmake will do this replacement on deploy, but this is useful in development
if (runtimeBaseDir.find("${CMAKE_INSTALL_PREFIX}") >= 0)
runtimeBaseDir = replaceAll(runtimeBaseDir, "${CMAKE_INSTALL_PREFIX}", INSTALL_PREFIX);
std::string detectorString = getString(ini, defaultIni, "", "detector", "lbpcpu");
std::transform(detectorString.begin(), detectorString.end(), detectorString.begin(), ::tolower);

View File

@@ -613,6 +613,15 @@ int levenshteinDistance (const std::string &s1, const std::string &s2, int max)
return ss.str();
}
std::string replaceAll(std::string str, const std::string& from, const std::string& to) {
size_t start_pos = 0;
while((start_pos = str.find(from, start_pos)) != std::string::npos) {
str.replace(start_pos, from.length(), to);
start_pos += to.length(); // Handles case where 'to' is a substring of 'from'
}
return str;
}
// trim from start
std::string &ltrim(std::string &s) {
s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));

View File

@@ -115,6 +115,8 @@ namespace alpr
std::string toString(float value);
std::string toString(double value);
std::string replaceAll(std::string str, const std::string& from, const std::string& to);
std::string &ltrim(std::string &s);
std::string &rtrim(std::string &s);
std::string &trim(std::string &s);