From 111562822d978568e794754db26aad4bc9c50a16 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Mon, 18 Nov 2019 09:31:46 +0800 Subject: [PATCH] Add handy startsWith string utility function --- code/nel/include/nel/misc/string_common.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/code/nel/include/nel/misc/string_common.h b/code/nel/include/nel/misc/string_common.h index bb972a4eb..7366a0693 100644 --- a/code/nel/include/nel/misc/string_common.h +++ b/code/nel/include/nel/misc/string_common.h @@ -257,6 +257,20 @@ inline bool fromString(const std::string &str, uint &val) { return sscanf(str.c_ inline bool fromString(const std::string &str, sint &val) { return sscanf(str.c_str(), "%d", &val) == 1; } #endif // NL_COMP_VC6 +inline bool startsWith(const char *str, const char *prefix) +{ + for (int i = 0;; ++i) + { + if (str[i] != prefix[i] || str[i] == '\0') + { + return prefix[i] == '\0'; + } + } +} + +inline bool startsWith(const std::string &str, const char *prefix) { return startsWith(str.c_str(), prefix); } +inline bool startsWith(const std::string &str, const std::string &prefix) { return startsWith(str.c_str(), prefix.c_str()); } + // Convert local codepage to UTF-8 // On Windows, the local codepage is undetermined // On Linux, the local codepage is always UTF-8 (no-op)