Loading...
Searching...
No Matches
juce_StringRef.h
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2022 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
The code included in this file is provided under the terms of the ISC license
http://www.isc.org/downloads/software-support-policy/isc-license. Permission
To use, copy, modify, and/or distribute this software for any purpose with or
without fee is hereby granted provided that the above copyright notice and
this permission notice appear in all copies.
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
//==============================================================================
class JUCE_API StringRef final
{
public:
StringRef (const char* stringLiteral) noexcept;
StringRef (String::CharPointerType stringLiteral) noexcept;
StringRef (const String& string) noexcept;
StringRef (const std::string& string);
StringRef() noexcept;
//==============================================================================
operator const String::CharPointerType::CharType*() const noexcept { return text.getAddress(); }
operator String::CharPointerType() const noexcept { return text; }
bool isEmpty() const noexcept { return text.isEmpty(); }
bool isNotEmpty() const noexcept { return ! text.isEmpty(); }
int length() const noexcept { return (int) text.length(); }
juce_wchar operator[] (int index) const noexcept { return text[index]; }
bool operator== (const String& s) const noexcept { return text.compare (s.getCharPointer()) == 0; }
bool operator!= (const String& s) const noexcept { return text.compare (s.getCharPointer()) != 0; }
bool operator< (const String& s) const noexcept { return text.compare (s.getCharPointer()) < 0; }
bool operator<= (const String& s) const noexcept { return text.compare (s.getCharPointer()) <= 0; }
bool operator> (const String& s) const noexcept { return text.compare (s.getCharPointer()) > 0; }
bool operator>= (const String& s) const noexcept { return text.compare (s.getCharPointer()) >= 0; }
bool operator== (StringRef s) const noexcept { return text.compare (s.text) == 0; }
bool operator!= (StringRef s) const noexcept { return text.compare (s.text) != 0; }
//==============================================================================
String::CharPointerType text;
#if JUCE_STRING_UTF_TYPE != 8 && ! defined (DOXYGEN)
// Sorry, non-UTF8 people, you're unable to take advantage of StringRef, because
// you've chosen a character encoding that doesn't match C++ string literals.
String stringCopy;
#endif
};
//==============================================================================
JUCE_API bool JUCE_CALLTYPE operator== (const String& string1, StringRef string2) noexcept;
JUCE_API bool JUCE_CALLTYPE operator!= (const String& string1, StringRef string2) noexcept;
JUCE_API bool JUCE_CALLTYPE operator< (const String& string1, StringRef string2) noexcept;
JUCE_API bool JUCE_CALLTYPE operator<= (const String& string1, StringRef string2) noexcept;
JUCE_API bool JUCE_CALLTYPE operator> (const String& string1, StringRef string2) noexcept;
JUCE_API bool JUCE_CALLTYPE operator>= (const String& string1, StringRef string2) noexcept;
inline String operator+ (String s1, StringRef s2) { return s1 += String (s2.text); }
inline String operator+ (StringRef s1, const String& s2) { return String (s1.text) + s2; }
inline String operator+ (const char* s1, StringRef s2) { return String (s1) + String (s2.text); }
inline String operator+ (StringRef s1, const char* s2) { return String (s1.text) + String (s2); }
} // namespace juce
juce::StringRef
Definition juce_StringRef.h:62
juce::StringRef::isNotEmpty
bool isNotEmpty() const noexcept
Definition juce_StringRef.h:103
juce::StringRef::StringRef
StringRef(const char *stringLiteral) noexcept
Definition juce_String.cpp:2149
juce::StringRef::length
int length() const noexcept
Definition juce_StringRef.h:105
juce::StringRef::text
String::CharPointerType text
Definition juce_StringRef.h:130
juce::StringRef::isEmpty
bool isEmpty() const noexcept
Definition juce_StringRef.h:101
juce::String
Definition juce_String.h:53