openshot-audio  0.1.6
juce_CharPointer_UTF32.h
Go to the documentation of this file.
1 /*
2  ==============================================================================
3 
4  This file is part of the juce_core module of the JUCE library.
5  Copyright (c) 2015 - ROLI Ltd.
6 
7  Permission to use, copy, modify, and/or distribute this software for any purpose with
8  or without fee is hereby granted, provided that the above copyright notice and this
9  permission notice appear in all copies.
10 
11  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
12  TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
13  NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14  DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
15  IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
16  CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 
18  ------------------------------------------------------------------------------
19 
20  NOTE! This permissive ISC license applies ONLY to files within the juce_core module!
21  All other JUCE modules are covered by a dual GPL/commercial license, so if you are
22  using any other modules, be sure to check that you also comply with their license.
23 
24  For more details, visit www.juce.com
25 
26  ==============================================================================
27 */
28 
29 #ifndef JUCE_CHARPOINTER_UTF32_H_INCLUDED
30 #define JUCE_CHARPOINTER_UTF32_H_INCLUDED
31 
32 
33 //==============================================================================
40 {
41 public:
43 
44  inline explicit CharPointer_UTF32 (const CharType* const rawPointer) noexcept
45  : data (const_cast <CharType*> (rawPointer))
46  {
47  }
48 
50  : data (other.data)
51  {
52  }
53 
55  {
56  data = other.data;
57  return *this;
58  }
59 
60  inline CharPointer_UTF32 operator= (const CharType* text) noexcept
61  {
62  data = const_cast <CharType*> (text);
63  return *this;
64  }
65 
67  inline bool operator== (CharPointer_UTF32 other) const noexcept { return data == other.data; }
68  inline bool operator!= (CharPointer_UTF32 other) const noexcept { return data != other.data; }
69  inline bool operator<= (CharPointer_UTF32 other) const noexcept { return data <= other.data; }
70  inline bool operator< (CharPointer_UTF32 other) const noexcept { return data < other.data; }
71  inline bool operator>= (CharPointer_UTF32 other) const noexcept { return data >= other.data; }
72  inline bool operator> (CharPointer_UTF32 other) const noexcept { return data > other.data; }
73 
75  inline CharType* getAddress() const noexcept { return data; }
76 
78  inline operator const CharType*() const noexcept { return data; }
79 
81  inline bool isEmpty() const noexcept { return *data == 0; }
82 
84  inline juce_wchar operator*() const noexcept { return *data; }
85 
88  {
89  ++data;
90  return *this;
91  }
92 
95  {
96  --data;
97  return *this;
98  }
99 
102  inline juce_wchar getAndAdvance() noexcept { return *data++; }
103 
106  {
107  CharPointer_UTF32 temp (*this);
108  ++data;
109  return temp;
110  }
111 
113  inline void operator+= (const int numToSkip) noexcept
114  {
115  data += numToSkip;
116  }
117 
118  inline void operator-= (const int numToSkip) noexcept
119  {
120  data -= numToSkip;
121  }
122 
124  inline juce_wchar& operator[] (const int characterIndex) const noexcept
125  {
126  return data [characterIndex];
127  }
128 
130  CharPointer_UTF32 operator+ (const int numToSkip) const noexcept
131  {
132  return CharPointer_UTF32 (data + numToSkip);
133  }
134 
136  CharPointer_UTF32 operator- (const int numToSkip) const noexcept
137  {
138  return CharPointer_UTF32 (data - numToSkip);
139  }
140 
142  inline void write (const juce_wchar charToWrite) noexcept
143  {
144  *data++ = charToWrite;
145  }
146 
147  inline void replaceChar (const juce_wchar newChar) noexcept
148  {
149  *data = newChar;
150  }
151 
153  inline void writeNull() const noexcept
154  {
155  *data = 0;
156  }
157 
159  size_t length() const noexcept
160  {
161  #if JUCE_NATIVE_WCHAR_IS_UTF32 && ! JUCE_ANDROID
162  return wcslen (data);
163  #else
164  size_t n = 0;
165  while (data[n] != 0)
166  ++n;
167  return n;
168  #endif
169  }
170 
172  size_t lengthUpTo (const size_t maxCharsToCount) const noexcept
173  {
174  return CharacterFunctions::lengthUpTo (*this, maxCharsToCount);
175  }
176 
178  size_t lengthUpTo (const CharPointer_UTF32 end) const noexcept
179  {
180  return CharacterFunctions::lengthUpTo (*this, end);
181  }
182 
186  size_t sizeInBytes() const noexcept
187  {
188  return sizeof (CharType) * (length() + 1);
189  }
190 
194  static inline size_t getBytesRequiredFor (const juce_wchar) noexcept
195  {
196  return sizeof (CharType);
197  }
198 
203  template <class CharPointer>
204  static size_t getBytesRequiredFor (const CharPointer text) noexcept
205  {
206  return sizeof (CharType) * text.length();
207  }
208 
211  {
212  return CharPointer_UTF32 (data + length());
213  }
214 
216  template <typename CharPointer>
217  void writeAll (const CharPointer src) noexcept
218  {
219  CharacterFunctions::copyAll (*this, src);
220  }
221 
224  {
225  const CharType* s = src.data;
226 
227  while ((*data = *s) != 0)
228  {
229  ++data;
230  ++s;
231  }
232  }
233 
238  template <typename CharPointer>
239  size_t writeWithDestByteLimit (const CharPointer src, const size_t maxDestBytes) noexcept
240  {
241  return CharacterFunctions::copyWithDestByteLimit (*this, src, maxDestBytes);
242  }
243 
248  template <typename CharPointer>
249  void writeWithCharLimit (const CharPointer src, const int maxChars) noexcept
250  {
251  CharacterFunctions::copyWithCharLimit (*this, src, maxChars);
252  }
253 
255  template <typename CharPointer>
256  int compare (const CharPointer other) const noexcept
257  {
258  return CharacterFunctions::compare (*this, other);
259  }
260 
261  #if JUCE_NATIVE_WCHAR_IS_UTF32 && ! JUCE_ANDROID
262 
263  int compare (const CharPointer_UTF32 other) const noexcept
264  {
265  return wcscmp (data, other.data);
266  }
267  #endif
268 
270  template <typename CharPointer>
271  int compareUpTo (const CharPointer other, const int maxChars) const noexcept
272  {
273  return CharacterFunctions::compareUpTo (*this, other, maxChars);
274  }
275 
277  template <typename CharPointer>
278  int compareIgnoreCase (const CharPointer other) const
279  {
280  return CharacterFunctions::compareIgnoreCase (*this, other);
281  }
282 
284  template <typename CharPointer>
285  int compareIgnoreCaseUpTo (const CharPointer other, const int maxChars) const noexcept
286  {
287  return CharacterFunctions::compareIgnoreCaseUpTo (*this, other, maxChars);
288  }
289 
291  template <typename CharPointer>
292  int indexOf (const CharPointer stringToFind) const noexcept
293  {
294  return CharacterFunctions::indexOf (*this, stringToFind);
295  }
296 
298  int indexOf (const juce_wchar charToFind) const noexcept
299  {
300  int i = 0;
301 
302  while (data[i] != 0)
303  {
304  if (data[i] == charToFind)
305  return i;
306 
307  ++i;
308  }
309 
310  return -1;
311  }
312 
314  int indexOf (const juce_wchar charToFind, const bool ignoreCase) const noexcept
315  {
316  return ignoreCase ? CharacterFunctions::indexOfCharIgnoreCase (*this, charToFind)
317  : CharacterFunctions::indexOfChar (*this, charToFind);
318  }
319 
321  bool isWhitespace() const { return CharacterFunctions::isWhitespace (*data) != 0; }
323  bool isDigit() const { return CharacterFunctions::isDigit (*data) != 0; }
325  bool isLetter() const { return CharacterFunctions::isLetter (*data) != 0; }
327  bool isLetterOrDigit() const { return CharacterFunctions::isLetterOrDigit (*data) != 0; }
329  bool isUpperCase() const { return CharacterFunctions::isUpperCase (*data) != 0; }
331  bool isLowerCase() const { return CharacterFunctions::isLowerCase (*data) != 0; }
332 
337 
339  int getIntValue32() const noexcept { return CharacterFunctions::getIntValue <int, CharPointer_UTF32> (*this); }
341  int64 getIntValue64() const noexcept { return CharacterFunctions::getIntValue <int64, CharPointer_UTF32> (*this); }
342 
344  double getDoubleValue() const noexcept { return CharacterFunctions::getDoubleValue (*this); }
345 
348 
350  static bool canRepresent (juce_wchar character) noexcept
351  {
352  return ((unsigned int) character) < (unsigned int) 0x10ffff;
353  }
354 
356  static bool isValidString (const CharType* dataToTest, int maxBytesToRead)
357  {
358  maxBytesToRead /= (int) sizeof (CharType);
359 
360  while (--maxBytesToRead >= 0 && *dataToTest != 0)
361  if (! canRepresent (*dataToTest++))
362  return false;
363 
364  return true;
365  }
366 
369  {
370  return CharPointer_UTF32 (reinterpret_cast <Atomic<CharType*>&> (data).exchange (newValue.data));
371  }
372 
373 private:
374  CharType* data;
375 };
376 
377 
378 #endif // JUCE_CHARPOINTER_UTF32_H_INCLUDED
void write(const juce_wchar charToWrite) noexcept
Definition: juce_CharPointer_UTF32.h:142
double getDoubleValue() const noexcept
Definition: juce_CharPointer_UTF32.h:344
static size_t lengthUpTo(CharPointerType text, const size_t maxCharsToCount) noexcept
Definition: juce_CharacterFunctions.h:307
void replaceChar(const juce_wchar newChar) noexcept
Definition: juce_CharPointer_UTF32.h:147
void writeAll(const CharPointer src) noexcept
Definition: juce_CharPointer_UTF32.h:217
void writeWithCharLimit(const CharPointer src, const int maxChars) noexcept
Definition: juce_CharPointer_UTF32.h:249
#define noexcept
Definition: juce_CompilerSupport.h:141
Definition: juce_Atomic.h:41
static size_t getBytesRequiredFor(const CharPointer text) noexcept
Definition: juce_CharPointer_UTF32.h:204
static juce_wchar toLowerCase(juce_wchar character) noexcept
Definition: juce_CharacterFunctions.cpp:40
CharPointer_UTF32 operator+(const int numToSkip) const noexcept
Definition: juce_CharPointer_UTF32.h:130
bool isDigit() const
Definition: juce_CharPointer_UTF32.h:323
int64 getIntValue64() const noexcept
Definition: juce_CharPointer_UTF32.h:341
static int compare(CharPointerType1 s1, CharPointerType2 s2) noexcept
Definition: juce_CharacterFunctions.h:393
static Type findEndOfWhitespace(Type text) noexcept
Definition: juce_CharacterFunctions.h:586
CharPointer_UTF32 operator=(CharPointer_UTF32 other) noexcept
Definition: juce_CharPointer_UTF32.h:54
size_t lengthUpTo(const size_t maxCharsToCount) const noexcept
Definition: juce_CharPointer_UTF32.h:172
static size_t getBytesRequiredFor(const juce_wchar) noexcept
Definition: juce_CharPointer_UTF32.h:194
static double getDoubleValue(CharPointerType text) noexcept
Definition: juce_CharacterFunctions.h:253
bool isUpperCase() const
Definition: juce_CharPointer_UTF32.h:329
bool operator<=(CharPointer_UTF32 other) const noexcept
Definition: juce_CharPointer_UTF32.h:69
bool isLetterOrDigit() const
Definition: juce_CharPointer_UTF32.h:327
juce_wchar & operator[](const int characterIndex) const noexcept
Definition: juce_CharPointer_UTF32.h:124
bool operator==(CharPointer_UTF32 other) const noexcept
Definition: juce_CharPointer_UTF32.h:67
static bool isValidString(const CharType *dataToTest, int maxBytesToRead)
Definition: juce_CharPointer_UTF32.h:356
static bool isDigit(char character) noexcept
Definition: juce_CharacterFunctions.cpp:78
static bool isLetterOrDigit(char character) noexcept
Definition: juce_CharacterFunctions.cpp:99
bool operator>(CharPointer_UTF32 other) const noexcept
Definition: juce_CharPointer_UTF32.h:72
static bool isWhitespace(char character) noexcept
Definition: juce_CharacterFunctions.cpp:68
bool isEmpty() const noexcept
Definition: juce_CharPointer_UTF32.h:81
static juce_wchar toUpperCase(juce_wchar character) noexcept
Definition: juce_CharacterFunctions.cpp:35
int indexOf(const juce_wchar charToFind, const bool ignoreCase) const noexcept
Definition: juce_CharPointer_UTF32.h:314
static bool canRepresent(juce_wchar character) noexcept
Definition: juce_CharPointer_UTF32.h:350
static bool isLetter(char character) noexcept
Definition: juce_CharacterFunctions.cpp:88
size_t sizeInBytes() const noexcept
Definition: juce_CharPointer_UTF32.h:186
CharType * getAddress() const noexcept
Definition: juce_CharPointer_UTF32.h:75
bool operator!=(CharPointer_UTF32 other) const noexcept
Definition: juce_CharPointer_UTF32.h:68
static int indexOf(CharPointerType1 textToSearch, const CharPointerType2 substringToLookFor) noexcept
Definition: juce_CharacterFunctions.h:467
static void copyAll(DestCharPointerType &dest, SrcCharPointerType src) noexcept
Definition: juce_CharacterFunctions.h:332
static size_t copyWithDestByteLimit(DestCharPointerType &dest, SrcCharPointerType src, size_t maxBytesToWrite) noexcept
Definition: juce_CharacterFunctions.h:350
bool isLetter() const
Definition: juce_CharPointer_UTF32.h:325
CharPointer_UTF32 atomicSwap(const CharPointer_UTF32 newValue)
Definition: juce_CharPointer_UTF32.h:368
bool isLowerCase() const
Definition: juce_CharPointer_UTF32.h:331
bool operator<(CharPointer_UTF32 other) const noexcept
Definition: juce_CharPointer_UTF32.h:70
int indexOf(const juce_wchar charToFind) const noexcept
Definition: juce_CharPointer_UTF32.h:298
juce_wchar toUpperCase() const noexcept
Definition: juce_CharPointer_UTF32.h:334
void operator+=(const int numToSkip) noexcept
Definition: juce_CharPointer_UTF32.h:113
CharPointer_UTF32 findEndOfWhitespace() const noexcept
Definition: juce_CharPointer_UTF32.h:347
size_t length() const noexcept
Definition: juce_CharPointer_UTF32.h:159
static void copyWithCharLimit(DestCharPointerType &dest, SrcCharPointerType src, int maxChars) noexcept
Definition: juce_CharacterFunctions.h:377
CharPointer_UTF32(const CharType *const rawPointer) noexcept
Definition: juce_CharPointer_UTF32.h:44
bool isWhitespace() const
Definition: juce_CharPointer_UTF32.h:321
static int compareIgnoreCase(CharPointerType1 s1, CharPointerType2 s2) noexcept
Definition: juce_CharacterFunctions.h:427
void writeAll(const CharPointer_UTF32 src) noexcept
Definition: juce_CharPointer_UTF32.h:223
size_t lengthUpTo(const CharPointer_UTF32 end) const noexcept
Definition: juce_CharPointer_UTF32.h:178
int compareUpTo(const CharPointer other, const int maxChars) const noexcept
Definition: juce_CharPointer_UTF32.h:271
juce_wchar CharType
Definition: juce_CharPointer_UTF32.h:42
long long int64
Definition: juce_MathsFunctions.h:60
Definition: juce_CharPointer_UTF32.h:39
size_t writeWithDestByteLimit(const CharPointer src, const size_t maxDestBytes) noexcept
Definition: juce_CharPointer_UTF32.h:239
juce_wchar getAndAdvance() noexcept
Definition: juce_CharPointer_UTF32.h:102
int compareIgnoreCase(const CharPointer other) const
Definition: juce_CharPointer_UTF32.h:278
int getIntValue32() const noexcept
Definition: juce_CharPointer_UTF32.h:339
bool operator>=(CharPointer_UTF32 other) const noexcept
Definition: juce_CharPointer_UTF32.h:71
static int indexOfChar(Type text, const juce_wchar charToFind) noexcept
Definition: juce_CharacterFunctions.h:544
void operator-=(const int numToSkip) noexcept
Definition: juce_CharPointer_UTF32.h:118
int compare(const CharPointer other) const noexcept
Definition: juce_CharPointer_UTF32.h:256
static int compareUpTo(CharPointerType1 s1, CharPointerType2 s2, int maxChars) noexcept
Definition: juce_CharacterFunctions.h:410
static int indexOfCharIgnoreCase(Type text, juce_wchar charToFind) noexcept
Definition: juce_CharacterFunctions.h:564
juce_wchar toLowerCase() const noexcept
Definition: juce_CharPointer_UTF32.h:336
static bool isLowerCase(juce_wchar character) noexcept
Definition: juce_CharacterFunctions.cpp:54
CharPointer_UTF32 findTerminatingNull() const noexcept
Definition: juce_CharPointer_UTF32.h:210
CharPointer_UTF32 operator--() noexcept
Definition: juce_CharPointer_UTF32.h:94
CharPointer_UTF32(const CharPointer_UTF32 &other) noexcept
Definition: juce_CharPointer_UTF32.h:49
static bool isUpperCase(juce_wchar character) noexcept
Definition: juce_CharacterFunctions.cpp:45
int indexOf(const CharPointer stringToFind) const noexcept
Definition: juce_CharPointer_UTF32.h:292
void writeNull() const noexcept
Definition: juce_CharPointer_UTF32.h:153
static int compareIgnoreCaseUpTo(CharPointerType1 s1, CharPointerType2 s2, int maxChars) noexcept
Definition: juce_CharacterFunctions.h:446
wchar_t juce_wchar
Definition: juce_CharacterFunctions.h:49
CharPointer_UTF32 operator-(const int numToSkip) const noexcept
Definition: juce_CharPointer_UTF32.h:136
juce_wchar operator*() const noexcept
Definition: juce_CharPointer_UTF32.h:84
int compareIgnoreCaseUpTo(const CharPointer other, const int maxChars) const noexcept
Definition: juce_CharPointer_UTF32.h:285
CharPointer_UTF32 operator++() noexcept
Definition: juce_CharPointer_UTF32.h:87