aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/QUtil.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2021-02-18 13:55:39 +0100
committerJay Berkenbilt <ejb@ql.org>2021-02-18 15:59:03 +0100
commit0b1623d07db963ecf3789aba7163321812cba88e (patch)
tree93c9e387915ef9e8e500750a32f0ff650698f9ee /libqpdf/QUtil.cc
parentf21e4f264ab285817bfad1698dbb8b8b300c9ece (diff)
downloadqpdf-0b1623d07db963ecf3789aba7163321812cba88e.tar.zst
Add QUtil::path_basename
Diffstat (limited to 'libqpdf/QUtil.cc')
-rw-r--r--libqpdf/QUtil.cc31
1 files changed, 31 insertions, 0 deletions
diff --git a/libqpdf/QUtil.cc b/libqpdf/QUtil.cc
index a3fa94f4..17b163f5 100644
--- a/libqpdf/QUtil.cc
+++ b/libqpdf/QUtil.cc
@@ -663,6 +663,37 @@ QUtil::file_provider(std::string const& filename)
};
}
+std::string
+QUtil::path_basename(std::string const& filename)
+{
+#ifdef _WIN32
+ char const* pathsep = "/\\";
+#else
+ char const* pathsep = "/";
+#endif
+ std::string last = filename;
+ auto len = last.length();
+ while (len > 1)
+ {
+ auto pos = last.find_last_of(pathsep);
+ if (pos == len - 1)
+ {
+ last.pop_back();
+ --len;
+ }
+ else if (pos == std::string::npos)
+ {
+ break;
+ }
+ else
+ {
+ last = last.substr(pos + 1);
+ break;
+ }
+ }
+ return last;
+}
+
char*
QUtil::copy_string(std::string const& str)
{