Skip to content
Snippets Groups Projects
Commit 833ae9d5 authored by Tom Fischer's avatar Tom Fischer
Browse files

[BL] Use std::string::size_type to store positions.

This removes the clang sanitizer error "runtime error: unsigned integer overflow: 0 - 1 cannot be represented in type 'size_type' (aka 'unsigned long')" in the test
parent 304cfd65
No related branches found
No related tags found
No related merge requests found
...@@ -62,7 +62,7 @@ void truncateFile( std::string const& filename) ...@@ -62,7 +62,7 @@ void truncateFile( std::string const& filename)
* found. * found.
*/ */
static static
std::size_t findLastPathSeparator(std::string const& path) std::string::size_type findLastPathSeparator(std::string const& path)
{ {
return path.find_last_of("/\\"); return path.find_last_of("/\\");
} }
...@@ -71,7 +71,7 @@ std::size_t findLastPathSeparator(std::string const& path) ...@@ -71,7 +71,7 @@ std::size_t findLastPathSeparator(std::string const& path)
* This could be used to extract file extension. * This could be used to extract file extension.
*/ */
static static
std::size_t findLastDot(std::string const& path) std::string::size_type findLastDot(std::string const& path)
{ {
return path.find_last_of("."); return path.find_last_of(".");
} }
...@@ -79,12 +79,12 @@ std::size_t findLastDot(std::string const& path) ...@@ -79,12 +79,12 @@ std::size_t findLastDot(std::string const& path)
std::string dropFileExtension(std::string const& filename) std::string dropFileExtension(std::string const& filename)
{ {
// Look for dots in filename. // Look for dots in filename.
const std::size_t p = findLastDot(filename); auto const p = findLastDot(filename);
if (p == std::string::npos) if (p == std::string::npos)
return filename; return filename;
// Check position of the last path separator. // Check position of the last path separator.
const std::size_t s = findLastPathSeparator(filename); auto const s = findLastPathSeparator(filename);
if (s != std::string::npos && p < s) if (s != std::string::npos && p < s)
return filename; return filename;
...@@ -93,7 +93,7 @@ std::string dropFileExtension(std::string const& filename) ...@@ -93,7 +93,7 @@ std::string dropFileExtension(std::string const& filename)
std::string extractBaseName(std::string const& pathname) std::string extractBaseName(std::string const& pathname)
{ {
const std::size_t p = findLastPathSeparator(pathname); auto const p = findLastPathSeparator(pathname);
if (p == std::string::npos) if (p == std::string::npos)
return pathname; return pathname;
return pathname.substr(p + 1); return pathname.substr(p + 1);
...@@ -108,7 +108,7 @@ std::string extractBaseNameWithoutExtension(std::string const& pathname) ...@@ -108,7 +108,7 @@ std::string extractBaseNameWithoutExtension(std::string const& pathname)
std::string getFileExtension(const std::string &path) std::string getFileExtension(const std::string &path)
{ {
const std::string str = extractBaseName(path); const std::string str = extractBaseName(path);
const std::size_t p = findLastDot(str); auto const p = findLastDot(str);
if (p == std::string::npos) if (p == std::string::npos)
return std::string(); return std::string();
return str.substr(p + 1); return str.substr(p + 1);
...@@ -123,7 +123,7 @@ std::string copyPathToFileName(const std::string &file_name, ...@@ -123,7 +123,7 @@ std::string copyPathToFileName(const std::string &file_name,
const std::string &source) const std::string &source)
{ {
// check if file_name already contains a full path // check if file_name already contains a full path
const std::size_t pos = findLastPathSeparator(file_name); auto const pos = findLastPathSeparator(file_name);
if (pos != std::string::npos) if (pos != std::string::npos)
return file_name; return file_name;
...@@ -132,7 +132,7 @@ std::string copyPathToFileName(const std::string &file_name, ...@@ -132,7 +132,7 @@ std::string copyPathToFileName(const std::string &file_name,
std::string extractPath(std::string const& pathname) std::string extractPath(std::string const& pathname)
{ {
const std::size_t pos = findLastPathSeparator(pathname); auto const pos = findLastPathSeparator(pathname);
if (pos == std::string::npos) if (pos == std::string::npos)
return ""; return "";
return pathname.substr(0, pos + 1); return pathname.substr(0, pos + 1);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment