summaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <bjorn@lindeijer.nl>2025-07-10 17:11:07 +0200
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2025-07-11 20:50:41 +0200
commite09248620ad430fbbd907dab5e54fe96fd69baa9 (patch)
treebaf1508e7bfa076069311177bd06260d74bfc029 /src/utils
parent6b89b661df1a2682edfa491e1bb9a21c4ab0943c (diff)
downloadmana-master.tar.gz
mana-master.tar.bz2
mana-master.tar.xz
mana-master.zip
Make the screenshot file name a clickable linkHEADmaster
Some security checks are done because players might also write "screenshot:" in the chat to create file:// URLs and `SDL_OpenURL` can be used to open many things. So we disallow ".." and require a ".png" extension.
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/stringutils.h13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h
index 8dd4454a..885ddcb8 100644
--- a/src/utils/stringutils.h
+++ b/src/utils/stringutils.h
@@ -117,9 +117,18 @@ std::string &removeColors(std::string &msg);
/**
* Returns whether a string starts with a given prefix.
*/
-inline bool startsWith(const std::string &str, const char *prefix)
+inline bool startsWith(std::string_view str, std::string_view prefix)
{
- return str.rfind(prefix, 0) == 0;
+ return str.substr(0, prefix.size()) == prefix;
+}
+
+/**
+ * Returns whether a string ends with a given suffix.
+ */
+inline bool endsWith(std::string_view str, std::string_view suffix)
+{
+ return str.size() >= suffix.size() &&
+ str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0;
}
/**