openshot-audio  0.1.2
juce_CharPointer_ASCII.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_ASCII_H_INCLUDED
30 #define JUCE_CHARPOINTER_ASCII_H_INCLUDED
31 
32 
33 //==============================================================================
43 {
44 public:
45  typedef char CharType;
46 
47  inline explicit CharPointer_ASCII (const CharType* const rawPointer) noexcept
48  : data (const_cast <CharType*> (rawPointer))
49  {
50  }
51 
53  : data (other.data)
54  {
55  }
56 
58  {
59  data = other.data;
60  return *this;
61  }
62 
63  inline CharPointer_ASCII operator= (const CharType* text) noexcept
64  {
65  data = const_cast <CharType*> (text);
66  return *this;
67  }
68 
70  inline bool operator== (CharPointer_ASCII other) const noexcept { return data == other.data; }
71  inline bool operator!= (CharPointer_ASCII other) const noexcept { return data != other.data; }
72  inline bool operator<= (CharPointer_ASCII other) const noexcept { return data <= other.data; }
73  inline bool operator< (CharPointer_ASCII other) const noexcept { return data < other.data; }
74  inline bool operator>= (CharPointer_ASCII other) const noexcept { return data >= other.data; }
75  inline bool operator> (CharPointer_ASCII other) const noexcept { return data > other.data; }
76 
78  inline CharType* getAddress() const noexcept { return data; }
79 
81  inline operator const CharType*() const noexcept { return data; }
82 
84  inline bool isEmpty() const noexcept { return *data == 0; }
85 
87  inline juce_wchar operator*() const noexcept { return (juce_wchar) (uint8) *data; }
88 
91  {
92  ++data;
93  return *this;
94  }
95 
98  {
99  --data;
100  return *this;
101  }
102 
105  inline juce_wchar getAndAdvance() noexcept { return (juce_wchar) (uint8) *data++; }
106 
109  {
110  CharPointer_ASCII temp (*this);
111  ++data;
112  return temp;
113  }
114 
116  inline void operator+= (const int numToSkip) noexcept
117  {
118  data += numToSkip;
119  }
120 
121  inline void operator-= (const int numToSkip) noexcept
122  {
123  data -= numToSkip;
124  }
125 
127  inline juce_wchar operator[] (const int characterIndex) const noexcept
128  {
129  return (juce_wchar) (unsigned char) data [characterIndex];
130  }
131 
133  CharPointer_ASCII operator+ (const int numToSkip) const noexcept
134  {
135  return CharPointer_ASCII (data + numToSkip);
136  }
137 
139  CharPointer_ASCII operator- (const int numToSkip) const noexcept
140  {
141  return CharPointer_ASCII (data - numToSkip);
142  }
143 
145  inline void write (const juce_wchar charToWrite) noexcept
146  {
147  *data++ = (char) charToWrite;
148  }
149 
150  inline void replaceChar (const juce_wchar newChar) noexcept
151  {
152  *data = (char) newChar;
153  }
154 
156  inline void writeNull() const noexcept
157  {
158  *data = 0;
159  }
160 
162  size_t length() const noexcept
163  {
164  return (size_t) strlen (data);
165  }
166 
168  size_t lengthUpTo (const size_t maxCharsToCount) const noexcept
169  {
170  return CharacterFunctions::lengthUpTo (*this, maxCharsToCount);
171  }
172 
174  size_t lengthUpTo (const CharPointer_ASCII end) const noexcept
175  {
176  return CharacterFunctions::lengthUpTo (*this, end);
177  }
178 
182  size_t sizeInBytes() const noexcept
183  {
184  return length() + 1;
185  }
186 
190  static inline size_t getBytesRequiredFor (const juce_wchar) noexcept
191  {
192  return 1;
193  }
194 
199  template <class CharPointer>
200  static size_t getBytesRequiredFor (const CharPointer text) noexcept
201  {
202  return text.length();
203  }
204 
207  {
208  return CharPointer_ASCII (data + length());
209  }
210 
212  template <typename CharPointer>
213  void writeAll (const CharPointer src) noexcept
214  {
215  CharacterFunctions::copyAll (*this, src);
216  }
217 
220  {
221  strcpy (data, src.data);
222  }
223 
228  template <typename CharPointer>
229  size_t writeWithDestByteLimit (const CharPointer src, const size_t maxDestBytes) noexcept
230  {
231  return CharacterFunctions::copyWithDestByteLimit (*this, src, maxDestBytes);
232  }
233 
238  template <typename CharPointer>
239  void writeWithCharLimit (const CharPointer src, const int maxChars) noexcept
240  {
241  CharacterFunctions::copyWithCharLimit (*this, src, maxChars);
242  }
243 
245  template <typename CharPointer>
246  int compare (const CharPointer other) const noexcept
247  {
248  return CharacterFunctions::compare (*this, other);
249  }
250 
252  int compare (const CharPointer_ASCII other) const noexcept
253  {
254  return strcmp (data, other.data);
255  }
256 
258  template <typename CharPointer>
259  int compareUpTo (const CharPointer other, const int maxChars) const noexcept
260  {
261  return CharacterFunctions::compareUpTo (*this, other, maxChars);
262  }
263 
265  int compareUpTo (const CharPointer_ASCII other, const int maxChars) const noexcept
266  {
267  return strncmp (data, other.data, (size_t) maxChars);
268  }
269 
271  template <typename CharPointer>
272  int compareIgnoreCase (const CharPointer other) const
273  {
274  return CharacterFunctions::compareIgnoreCase (*this, other);
275  }
276 
277  int compareIgnoreCase (const CharPointer_ASCII other) const
278  {
279  #if JUCE_MSVC
280  return stricmp (data, other.data);
281  #elif JUCE_MINGW
282  return CharacterFunctions::compareIgnoreCase (*this, other);
283  #else
284  return strcasecmp (data, other.data);
285  #endif
286  }
287 
289  template <typename CharPointer>
290  int compareIgnoreCaseUpTo (const CharPointer other, const int maxChars) const noexcept
291  {
292  return CharacterFunctions::compareIgnoreCaseUpTo (*this, other, maxChars);
293  }
294 
296  template <typename CharPointer>
297  int indexOf (const CharPointer stringToFind) const noexcept
298  {
299  return CharacterFunctions::indexOf (*this, stringToFind);
300  }
301 
303  int indexOf (const juce_wchar charToFind) const noexcept
304  {
305  int i = 0;
306 
307  while (data[i] != 0)
308  {
309  if (data[i] == (char) charToFind)
310  return i;
311 
312  ++i;
313  }
314 
315  return -1;
316  }
317 
319  int indexOf (const juce_wchar charToFind, const bool ignoreCase) const noexcept
320  {
321  return ignoreCase ? CharacterFunctions::indexOfCharIgnoreCase (*this, charToFind)
322  : CharacterFunctions::indexOfChar (*this, charToFind);
323  }
324 
326  bool isWhitespace() const { return CharacterFunctions::isWhitespace (*data) != 0; }
328  bool isDigit() const { return CharacterFunctions::isDigit (*data) != 0; }
330  bool isLetter() const { return CharacterFunctions::isLetter (*data) != 0; }
332  bool isLetterOrDigit() const { return CharacterFunctions::isLetterOrDigit (*data) != 0; }
334  bool isUpperCase() const { return CharacterFunctions::isUpperCase ((juce_wchar) (uint8) *data) != 0; }
336  bool isLowerCase() const { return CharacterFunctions::isLowerCase ((juce_wchar) (uint8) *data) != 0; }
337 
342 
344  int getIntValue32() const noexcept { return atoi (data); }
345 
348  {
349  #if JUCE_LINUX || JUCE_ANDROID || JUCE_MINGW
350  return atoll (data);
351  #elif JUCE_WINDOWS
352  return _atoi64 (data);
353  #else
354  return CharacterFunctions::getIntValue <int64, CharPointer_ASCII> (*this);
355  #endif
356  }
357 
359  double getDoubleValue() const noexcept { return CharacterFunctions::getDoubleValue (*this); }
360 
363 
365  static bool canRepresent (juce_wchar character) noexcept
366  {
367  return ((unsigned int) character) < (unsigned int) 128;
368  }
369 
371  static bool isValidString (const CharType* dataToTest, int maxBytesToRead)
372  {
373  while (--maxBytesToRead >= 0)
374  {
375  if (((signed char) *dataToTest) <= 0)
376  return *dataToTest == 0;
377 
378  ++dataToTest;
379  }
380 
381  return true;
382  }
383 
384 private:
385  CharType* data;
386 };
387 
388 
389 #endif // JUCE_CHARPOINTER_ASCII_H_INCLUDED
static size_t getBytesRequiredFor(const CharPointer text) noexcept
Definition: juce_CharPointer_ASCII.h:200
void operator+=(const int numToSkip) noexcept
Definition: juce_CharPointer_ASCII.h:116
juce_wchar getAndAdvance() noexcept
Definition: juce_CharPointer_ASCII.h:105
void writeNull() const noexcept
Definition: juce_CharPointer_ASCII.h:156
static size_t lengthUpTo(CharPointerType text, const size_t maxCharsToCount) noexcept
Definition: juce_CharacterFunctions.h:307
juce_wchar operator[](const int characterIndex) const noexcept
Definition: juce_CharPointer_ASCII.h:127
void write(const juce_wchar charToWrite) noexcept
Definition: juce_CharPointer_ASCII.h:145
juce_wchar toLowerCase() const noexcept
Definition: juce_CharPointer_ASCII.h:341
int compareIgnoreCase(const CharPointer other) const
Definition: juce_CharPointer_ASCII.h:272
bool operator==(CharPointer_ASCII other) const noexcept
Definition: juce_CharPointer_ASCII.h:70
static bool isValidString(const CharType *dataToTest, int maxBytesToRead)
Definition: juce_CharPointer_ASCII.h:371
CharPointer_ASCII operator--() noexcept
Definition: juce_CharPointer_ASCII.h:97
#define noexcept
Definition: juce_CompilerSupport.h:141
bool operator!=(CharPointer_ASCII other) const noexcept
Definition: juce_CharPointer_ASCII.h:71
static juce_wchar toLowerCase(juce_wchar character) noexcept
Definition: juce_CharacterFunctions.cpp:40
juce_wchar operator*() const noexcept
Definition: juce_CharPointer_ASCII.h:87
int64 getIntValue64() const noexcept
Definition: juce_CharPointer_ASCII.h:347
void writeAll(const CharPointer src) noexcept
Definition: juce_CharPointer_ASCII.h:213
static int compare(CharPointerType1 s1, CharPointerType2 s2) noexcept
Definition: juce_CharacterFunctions.h:393
static Type findEndOfWhitespace(Type text) noexcept
Definition: juce_CharacterFunctions.h:586
static double getDoubleValue(CharPointerType text) noexcept
Definition: juce_CharacterFunctions.h:253
bool operator>(CharPointer_ASCII other) const noexcept
Definition: juce_CharPointer_ASCII.h:75
int indexOf(const juce_wchar charToFind, const bool ignoreCase) const noexcept
Definition: juce_CharPointer_ASCII.h:319
int compare(const CharPointer other) const noexcept
Definition: juce_CharPointer_ASCII.h:246
double getDoubleValue() const noexcept
Definition: juce_CharPointer_ASCII.h:359
static bool isDigit(char character) noexcept
Definition: juce_CharacterFunctions.cpp:78
static bool isLetterOrDigit(char character) noexcept
Definition: juce_CharacterFunctions.cpp:99
int compareIgnoreCaseUpTo(const CharPointer other, const int maxChars) const noexcept
Definition: juce_CharPointer_ASCII.h:290
static bool isWhitespace(char character) noexcept
Definition: juce_CharacterFunctions.cpp:68
static juce_wchar toUpperCase(juce_wchar character) noexcept
Definition: juce_CharacterFunctions.cpp:35
bool isLowerCase() const
Definition: juce_CharPointer_ASCII.h:336
static bool isLetter(char character) noexcept
Definition: juce_CharacterFunctions.cpp:88
bool isLetter() const
Definition: juce_CharPointer_ASCII.h:330
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
CharPointer_ASCII findEndOfWhitespace() const noexcept
Definition: juce_CharPointer_ASCII.h:362
char CharType
Definition: juce_CharPointer_ASCII.h:45
size_t length() const noexcept
Definition: juce_CharPointer_ASCII.h:162
int getIntValue32() const noexcept
Definition: juce_CharPointer_ASCII.h:344
CharType * getAddress() const noexcept
Definition: juce_CharPointer_ASCII.h:78
CharPointer_ASCII operator=(const CharPointer_ASCII other) noexcept
Definition: juce_CharPointer_ASCII.h:57
bool operator<(CharPointer_ASCII other) const noexcept
Definition: juce_CharPointer_ASCII.h:73
static void copyWithCharLimit(DestCharPointerType &dest, SrcCharPointerType src, int maxChars) noexcept
Definition: juce_CharacterFunctions.h:377
CharPointer_ASCII operator+(const int numToSkip) const noexcept
Definition: juce_CharPointer_ASCII.h:133
int compareUpTo(const CharPointer other, const int maxChars) const noexcept
Definition: juce_CharPointer_ASCII.h:259
size_t lengthUpTo(const CharPointer_ASCII end) const noexcept
Definition: juce_CharPointer_ASCII.h:174
CharPointer_ASCII findTerminatingNull() const noexcept
Definition: juce_CharPointer_ASCII.h:206
int compareIgnoreCase(const CharPointer_ASCII other) const
Definition: juce_CharPointer_ASCII.h:277
static int compareIgnoreCase(CharPointerType1 s1, CharPointerType2 s2) noexcept
Definition: juce_CharacterFunctions.h:427
long long int64
Definition: juce_MathsFunctions.h:60
Definition: juce_CharPointer_ASCII.h:42
CharPointer_ASCII operator-(const int numToSkip) const noexcept
Definition: juce_CharPointer_ASCII.h:139
bool operator>=(CharPointer_ASCII other) const noexcept
Definition: juce_CharPointer_ASCII.h:74
bool isWhitespace() const
Definition: juce_CharPointer_ASCII.h:326
CharPointer_ASCII operator++() noexcept
Definition: juce_CharPointer_ASCII.h:90
static int indexOfChar(Type text, const juce_wchar charToFind) noexcept
Definition: juce_CharacterFunctions.h:544
CharPointer_ASCII(const CharPointer_ASCII &other) noexcept
Definition: juce_CharPointer_ASCII.h:52
CharPointer_ASCII(const CharType *const rawPointer) noexcept
Definition: juce_CharPointer_ASCII.h:47
void operator-=(const int numToSkip) noexcept
Definition: juce_CharPointer_ASCII.h:121
bool isLetterOrDigit() const
Definition: juce_CharPointer_ASCII.h:332
void writeAll(const CharPointer_ASCII src) noexcept
Definition: juce_CharPointer_ASCII.h:219
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
static size_t getBytesRequiredFor(const juce_wchar) noexcept
Definition: juce_CharPointer_ASCII.h:190
static bool isLowerCase(juce_wchar character) noexcept
Definition: juce_CharacterFunctions.cpp:54
static bool canRepresent(juce_wchar character) noexcept
Definition: juce_CharPointer_ASCII.h:365
size_t writeWithDestByteLimit(const CharPointer src, const size_t maxDestBytes) noexcept
Definition: juce_CharPointer_ASCII.h:229
int compareUpTo(const CharPointer_ASCII other, const int maxChars) const noexcept
Definition: juce_CharPointer_ASCII.h:265
size_t sizeInBytes() const noexcept
Definition: juce_CharPointer_ASCII.h:182
static bool isUpperCase(juce_wchar character) noexcept
Definition: juce_CharacterFunctions.cpp:45
static int compareIgnoreCaseUpTo(CharPointerType1 s1, CharPointerType2 s2, int maxChars) noexcept
Definition: juce_CharacterFunctions.h:446
int indexOf(const CharPointer stringToFind) const noexcept
Definition: juce_CharPointer_ASCII.h:297
bool operator<=(CharPointer_ASCII other) const noexcept
Definition: juce_CharPointer_ASCII.h:72
juce_wchar toUpperCase() const noexcept
Definition: juce_CharPointer_ASCII.h:339
int compare(const CharPointer_ASCII other) const noexcept
Definition: juce_CharPointer_ASCII.h:252
bool isUpperCase() const
Definition: juce_CharPointer_ASCII.h:334
bool isEmpty() const noexcept
Definition: juce_CharPointer_ASCII.h:84
unsigned char uint8
Definition: juce_MathsFunctions.h:43
int indexOf(const juce_wchar charToFind) const noexcept
Definition: juce_CharPointer_ASCII.h:303
wchar_t juce_wchar
Definition: juce_CharacterFunctions.h:49
size_t lengthUpTo(const size_t maxCharsToCount) const noexcept
Definition: juce_CharPointer_ASCII.h:168
void replaceChar(const juce_wchar newChar) noexcept
Definition: juce_CharPointer_ASCII.h:150
void writeWithCharLimit(const CharPointer src, const int maxChars) noexcept
Definition: juce_CharPointer_ASCII.h:239
bool isDigit() const
Definition: juce_CharPointer_ASCII.h:328