Core/StringExt: Don't pass string_view by ref
https://quuxplusone.github.io/blog/2021/11/09/pass-string-view-by-value/
This commit is contained in:
@@ -26,7 +26,7 @@ namespace Nz
|
||||
template<typename T> ByteArray ComputeHash(HashType hash, T&& v);
|
||||
template<typename T> ByteArray ComputeHash(AbstractHash& hash, T&& v);
|
||||
|
||||
inline bool HashAppend(AbstractHash* hash, const std::string_view& v);
|
||||
inline bool HashAppend(AbstractHash* hash, std::string_view v);
|
||||
|
||||
template<typename T>
|
||||
bool Serialize(SerializationContext& context, T&& value);
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace Nz
|
||||
return hash.End();
|
||||
}
|
||||
|
||||
inline bool HashAppend(AbstractHash& hash, const std::string_view& v)
|
||||
inline bool HashAppend(AbstractHash& hash, std::string_view v)
|
||||
{
|
||||
hash.Append(reinterpret_cast<const UInt8*>(v.data()), v.size());
|
||||
return true;
|
||||
|
||||
@@ -43,8 +43,8 @@ namespace Nz
|
||||
template<typename... Args> static void Write(std::string_view str, Args&&... args);
|
||||
static void WriteError(ErrorType type, std::string_view error, unsigned int line = 0, const char* file = nullptr, const char* function = nullptr);
|
||||
|
||||
NazaraStaticSignal(OnLogWrite, const std::string_view& /*string*/);
|
||||
NazaraStaticSignal(OnLogWriteError, ErrorType /*type*/, const std::string_view& /*error*/, unsigned int /*line*/, const char* /*file*/, const char* /*function*/);
|
||||
NazaraStaticSignal(OnLogWrite, std::string_view /*string*/);
|
||||
NazaraStaticSignal(OnLogWriteError, ErrorType /*type*/, std::string_view /*error*/, unsigned int /*line*/, const char* /*file*/, const char* /*function*/);
|
||||
|
||||
private:
|
||||
static bool Initialize();
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace Nz
|
||||
|
||||
void Clear();
|
||||
|
||||
bool IsExtensionSupported(const std::string_view& extension) const;
|
||||
bool IsExtensionSupported(std::string_view extension) const;
|
||||
|
||||
std::shared_ptr<Type> LoadFromFile(const std::filesystem::path& filePath, const Parameters& parameters = Parameters()) const;
|
||||
std::shared_ptr<Type> LoadFromMemory(const void* data, std::size_t size, const Parameters& parameters = Parameters()) const;
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace Nz
|
||||
* \param extension Extension of the file (ex: ".png")
|
||||
*/
|
||||
template<typename Type, typename Parameters>
|
||||
bool ResourceLoader<Type, Parameters>::IsExtensionSupported(const std::string_view& extension) const
|
||||
bool ResourceLoader<Type, Parameters>::IsExtensionSupported(std::string_view extension) const
|
||||
{
|
||||
NazaraAssert(extension.size() >= 2 || extension.front() != '.', "extension should start with a .");
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace Nz
|
||||
|
||||
public:
|
||||
struct Entry;
|
||||
using FormatSupport = std::function<bool(const std::string_view& format)>;
|
||||
using FormatSupport = std::function<bool(std::string_view format)>;
|
||||
using FileSaver = std::function<bool(const Type& resource, const std::filesystem::path& filePath, const Parameters& parameters)>;
|
||||
using StreamSaver = std::function<bool(const Type& resource, const std::string& format, Stream& stream, const Parameters& parameters)>;
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace Nz
|
||||
|
||||
void Clear();
|
||||
|
||||
bool IsExtensionSupported(const std::string_view& extension) const;
|
||||
bool IsExtensionSupported(std::string_view extension) const;
|
||||
|
||||
bool SaveToFile(const Type& resource, const std::filesystem::path& filePath, const Parameters& parameters = Parameters()) const;
|
||||
bool SaveToStream(const Type& resource, Stream& stream, const std::string& format, const Parameters& parameters = Parameters()) const;
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace Nz
|
||||
* \param extension Extension of the file
|
||||
*/
|
||||
template<typename Type, typename Parameters>
|
||||
bool ResourceSaver<Type, Parameters>::IsExtensionSupported(const std::string_view& extension) const
|
||||
bool ResourceSaver<Type, Parameters>::IsExtensionSupported(std::string_view extension) const
|
||||
{
|
||||
NazaraAssert(extension.size() >= 2 || extension.front() != '.', "extension should start with a .");
|
||||
|
||||
|
||||
@@ -18,55 +18,55 @@ namespace Nz
|
||||
struct UnicodeAware {};
|
||||
|
||||
// std::string is assumed to contains UTF-8
|
||||
NAZARA_CORE_API std::size_t ComputeCharacterCount(const std::string_view& str);
|
||||
NAZARA_CORE_API std::size_t ComputeCharacterCount(std::string_view str);
|
||||
|
||||
inline bool EndsWith(const std::string_view& str, const std::string_view& s);
|
||||
NAZARA_CORE_API bool EndsWith(const std::string_view& lhs, const std::string_view& rhs, CaseIndependent);
|
||||
NAZARA_CORE_API bool EndsWith(const std::string_view& lhs, const std::string_view& rhs, UnicodeAware);
|
||||
NAZARA_CORE_API bool EndsWith(const std::string_view& lhs, const std::string_view& rhs, CaseIndependent, UnicodeAware);
|
||||
inline bool EndsWith(std::string_view str, std::string_view s);
|
||||
NAZARA_CORE_API bool EndsWith(std::string_view lhs, std::string_view rhs, CaseIndependent);
|
||||
NAZARA_CORE_API bool EndsWith(std::string_view lhs, std::string_view rhs, UnicodeAware);
|
||||
NAZARA_CORE_API bool EndsWith(std::string_view lhs, std::string_view rhs, CaseIndependent, UnicodeAware);
|
||||
|
||||
NAZARA_CORE_API std::string FromUtf16String(const std::u16string_view& u16str);
|
||||
NAZARA_CORE_API std::string FromUtf32String(const std::u32string_view& u32str);
|
||||
NAZARA_CORE_API std::string FromWideString(const std::wstring_view& str);
|
||||
NAZARA_CORE_API std::string FromUtf16String(std::u16string_view u16str);
|
||||
NAZARA_CORE_API std::string FromUtf32String(std::u32string_view u32str);
|
||||
NAZARA_CORE_API std::string FromWideString(std::wstring_view str);
|
||||
|
||||
NAZARA_CORE_API std::size_t GetCharacterPosition(const std::string_view& str, std::size_t characterIndex);
|
||||
NAZARA_CORE_API std::string_view GetWord(const std::string_view& str, std::size_t wordIndex);
|
||||
NAZARA_CORE_API std::string_view GetWord(const std::string_view& str, std::size_t wordIndex, UnicodeAware);
|
||||
NAZARA_CORE_API std::size_t GetCharacterPosition(std::string_view str, std::size_t characterIndex);
|
||||
NAZARA_CORE_API std::string_view GetWord(std::string_view str, std::size_t wordIndex);
|
||||
NAZARA_CORE_API std::string_view GetWord(std::string_view str, std::size_t wordIndex, UnicodeAware);
|
||||
|
||||
inline bool IsNumber(std::string_view str);
|
||||
|
||||
NAZARA_CORE_API bool MatchPattern(const std::string_view& str, const std::string_view& pattern);
|
||||
NAZARA_CORE_API bool MatchPattern(std::string_view str, std::string_view pattern);
|
||||
|
||||
inline std::string NumberToString(long long number, UInt8 radix = 10);
|
||||
|
||||
NAZARA_CORE_API std::string PointerToString(const void* ptr);
|
||||
|
||||
inline std::string& ReplaceStr(std::string& str, const std::string_view& from, const std::string_view& to);
|
||||
inline std::string& ReplaceStr(std::string& str, std::string_view from, std::string_view to);
|
||||
|
||||
inline bool StartsWith(const std::string_view& str, const std::string_view& s);
|
||||
NAZARA_CORE_API bool StartsWith(const std::string_view& lhs, const std::string_view& rhs, CaseIndependent);
|
||||
NAZARA_CORE_API bool StartsWith(const std::string_view& lhs, const std::string_view& rhs, UnicodeAware);
|
||||
NAZARA_CORE_API bool StartsWith(const std::string_view& lhs, const std::string_view& rhs, CaseIndependent, UnicodeAware);
|
||||
inline bool StartsWith(std::string_view str, std::string_view s);
|
||||
NAZARA_CORE_API bool StartsWith(std::string_view lhs, std::string_view rhs, CaseIndependent);
|
||||
NAZARA_CORE_API bool StartsWith(std::string_view lhs, std::string_view rhs, UnicodeAware);
|
||||
NAZARA_CORE_API bool StartsWith(std::string_view lhs, std::string_view rhs, CaseIndependent, UnicodeAware);
|
||||
|
||||
template<typename F> bool SplitString(const std::string_view& str, const std::string_view& token, F&& func);
|
||||
template<typename F> bool SplitStringAny(const std::string_view& str, const std::string_view& token, F&& func);
|
||||
template<typename F> bool SplitString(std::string_view str, std::string_view token, F&& func);
|
||||
template<typename F> bool SplitStringAny(std::string_view str, std::string_view token, F&& func);
|
||||
|
||||
inline bool StringEqual(const std::string_view& lhs, const std::string_view& rhs);
|
||||
inline bool StringEqual(const std::string_view& lhs, const std::string_view& rhs, CaseIndependent);
|
||||
NAZARA_CORE_API bool StringEqual(const std::string_view& lhs, const std::string_view& rhs, UnicodeAware);
|
||||
NAZARA_CORE_API bool StringEqual(const std::string_view& lhs, const std::string_view& rhs, CaseIndependent, UnicodeAware);
|
||||
inline bool StringEqual(std::string_view lhs, std::string_view rhs);
|
||||
inline bool StringEqual(std::string_view lhs, std::string_view rhs, CaseIndependent);
|
||||
NAZARA_CORE_API bool StringEqual(std::string_view lhs, std::string_view rhs, UnicodeAware);
|
||||
NAZARA_CORE_API bool StringEqual(std::string_view lhs, std::string_view rhs, CaseIndependent, UnicodeAware);
|
||||
|
||||
inline long long StringToNumber(const std::string_view& str, UInt8 radix = 10, bool* ok = nullptr);
|
||||
inline long long StringToNumber(std::string_view str, UInt8 radix = 10, bool* ok = nullptr);
|
||||
|
||||
NAZARA_CORE_API std::string ToLower(const std::string_view& str);
|
||||
NAZARA_CORE_API std::string ToLower(const std::string_view& str, UnicodeAware);
|
||||
NAZARA_CORE_API std::string ToLower(std::string_view str);
|
||||
NAZARA_CORE_API std::string ToLower(std::string_view str, UnicodeAware);
|
||||
|
||||
NAZARA_CORE_API std::string ToUpper(const std::string_view& str);
|
||||
NAZARA_CORE_API std::string ToUpper(const std::string_view& str, UnicodeAware);
|
||||
NAZARA_CORE_API std::string ToUpper(std::string_view str);
|
||||
NAZARA_CORE_API std::string ToUpper(std::string_view str, UnicodeAware);
|
||||
|
||||
NAZARA_CORE_API std::u16string ToUtf16String(const std::string_view& str);
|
||||
NAZARA_CORE_API std::u32string ToUtf32String(const std::string_view& str);
|
||||
NAZARA_CORE_API std::wstring ToWideString(const std::string_view& str);
|
||||
NAZARA_CORE_API std::u16string ToUtf16String(std::string_view str);
|
||||
NAZARA_CORE_API std::u32string ToUtf32String(std::string_view str);
|
||||
NAZARA_CORE_API std::wstring ToWideString(std::string_view str);
|
||||
|
||||
inline std::string_view Trim(std::string_view str);
|
||||
inline std::string_view Trim(std::string_view str, char c);
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline bool EndsWith(const std::string_view& str, const std::string_view& s)
|
||||
inline bool EndsWith(std::string_view str, std::string_view s)
|
||||
{
|
||||
#if NAZARA_CPP_VER >= NAZARA_CPP20
|
||||
// C++20
|
||||
@@ -77,7 +77,7 @@ namespace Nz
|
||||
return str;
|
||||
}
|
||||
|
||||
inline std::string& ReplaceStr(std::string& str, const std::string_view& from, const std::string_view& to)
|
||||
inline std::string& ReplaceStr(std::string& str, std::string_view from, std::string_view to)
|
||||
{
|
||||
if (str.empty())
|
||||
return str;
|
||||
@@ -92,7 +92,7 @@ namespace Nz
|
||||
return str;
|
||||
}
|
||||
|
||||
inline bool StartsWith(const std::string_view& str, const std::string_view& s)
|
||||
inline bool StartsWith(std::string_view str, std::string_view s)
|
||||
{
|
||||
#if NAZARA_CPP_VER >= NAZARA_CPP20
|
||||
// C++20
|
||||
@@ -103,7 +103,7 @@ namespace Nz
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
bool SplitString(const std::string_view& str, const std::string_view& token, F&& func)
|
||||
bool SplitString(std::string_view str, std::string_view token, F&& func)
|
||||
{
|
||||
std::size_t pos = 0;
|
||||
std::size_t previousPos = 0;
|
||||
@@ -123,7 +123,7 @@ namespace Nz
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
bool SplitStringAny(const std::string_view& str, const std::string_view& token, F&& func)
|
||||
bool SplitStringAny(std::string_view str, std::string_view token, F&& func)
|
||||
{
|
||||
std::size_t pos = 0;
|
||||
std::size_t previousPos = 0;
|
||||
@@ -139,12 +139,12 @@ namespace Nz
|
||||
return func(str.substr(previousPos));
|
||||
}
|
||||
|
||||
inline bool StringEqual(const std::string_view& lhs, const std::string_view& rhs)
|
||||
inline bool StringEqual(std::string_view lhs, std::string_view rhs)
|
||||
{
|
||||
return lhs == rhs;
|
||||
}
|
||||
|
||||
inline bool StringEqual(const std::string_view& lhs, const std::string_view& rhs, CaseIndependent)
|
||||
inline bool StringEqual(std::string_view lhs, std::string_view rhs, CaseIndependent)
|
||||
{
|
||||
if (lhs.size() != rhs.size())
|
||||
return false;
|
||||
@@ -170,7 +170,7 @@ namespace Nz
|
||||
* \remark radix is meant to be between 2 and 36, other values are potentially undefined behavior
|
||||
* \remark With NAZARA_MATH_SAFE, a NazaraError is produced and 0 is returned
|
||||
*/
|
||||
inline long long StringToNumber(const std::string_view& str, UInt8 radix, bool* ok)
|
||||
inline long long StringToNumber(std::string_view str, UInt8 radix, bool* ok)
|
||||
{
|
||||
NazaraAssert(radix >= 2 && radix <= 36, "base must be between 2 and 36");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user