LMMS
Loading...
Searching...
No Matches
StringRef.h
Go to the documentation of this file.
1/*
2 ==============================================================================
3
4 This file is part of the Water library.
5 Copyright (c) 2016 ROLI Ltd.
6 Copyright (C) 2017-2022 Filipe Coelho <falktx@falktx.com>
7
8 Permission is granted to use this software under the terms of the ISC license
9 http://www.isc.org/downloads/software-support-policy/isc-license/
10
11 Permission to use, copy, modify, and/or distribute this software for any
12 purpose with or without fee is hereby granted, provided that the above
13 copyright notice and this permission notice appear in all copies.
14
15 THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
16 TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
18 OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
19 USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
20 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
21 OF THIS SOFTWARE.
22
23 ==============================================================================
24*/
25
26#ifndef WATER_STRINGREF_H_INCLUDED
27#define WATER_STRINGREF_H_INCLUDED
28
29#include "String.h"
30
31namespace water {
32
33//==============================================================================
67{
68public:
74 StringRef (const char* stringLiteral) noexcept;
75
80 StringRef (CharPointer_UTF8 stringLiteral) noexcept;
81
87 StringRef (const String& string) noexcept;
88
90 StringRef() noexcept;
91
92 //==============================================================================
94 operator const char*() const noexcept { return text.getAddress(); }
96 operator CharPointer_UTF8() const noexcept { return text; }
97
99 bool isEmpty() const noexcept { return text.isEmpty(); }
101 bool isNotEmpty() const noexcept { return ! text.isEmpty(); }
103 int length() const noexcept { return (int) text.length(); }
104
106 char operator[] (int index) const noexcept { return text[index]; }
107
109 bool operator== (const String& s) const noexcept { return text.compare (s.getCharPointer()) == 0; }
111 bool operator!= (const String& s) const noexcept { return text.compare (s.getCharPointer()) != 0; }
112
114 bool operator== (StringRef s) const noexcept { return text.compare (s.text) == 0; }
116 bool operator!= (StringRef s) const noexcept { return text.compare (s.text) != 0; }
117
118 //==============================================================================
121};
122
123//==============================================================================
125bool operator== (const String& string1, StringRef string2) noexcept;
127bool operator!= (const String& string1, StringRef string2) noexcept;
128
129inline String operator+ (String s1, StringRef s2) { return s1 += String (s2.text); }
130inline String operator+ (StringRef s1, const String& s2) { return String (s1.text) + s2; }
131inline String operator+ (const char* s1, StringRef s2) { return String (s1) + String (s2.text); }
132inline String operator+ (StringRef s1, const char* s2) { return String (s1.text) + String (s2); }
133
134}
135
136#endif // WATER_STRINGREF_H_INCLUDED
#define noexcept
Definition DistrhoDefines.h:72
Definition CharPointer_UTF8.h:45
Definition String.h:48
Definition StringRef.h:67
bool isEmpty() const noexcept
Definition StringRef.h:99
int length() const noexcept
Definition StringRef.h:103
bool operator==(const String &s) const noexcept
Definition StringRef.h:109
StringRef(const char *stringLiteral) noexcept
Definition String.cpp:2033
char operator[](int index) const noexcept
Definition StringRef.h:106
bool operator!=(const String &s) const noexcept
Definition StringRef.h:111
CharPointer_UTF8 text
Definition StringRef.h:120
StringRef() noexcept
Definition String.cpp:2029
bool isNotEmpty() const noexcept
Definition StringRef.h:101
unsigned s
Definition inflate.c:1555
Definition AudioSampleBuffer.h:33
bool operator==(const ReferenceCountedObjectPtr< ReferenceCountedObjectClass > &object1, ReferenceCountedObjectClass *const object2) noexcept
Definition ReferenceCountedObject.h:359
String operator+(const NewLine &, const NewLine &)
Definition NewLine.h:73
bool operator!=(const ReferenceCountedObjectPtr< ReferenceCountedObjectClass > &object1, const ReferenceCountedObjectClass *object2) noexcept
Definition ReferenceCountedObject.h:380
#define const
Definition zconf.h:137