26#ifndef WATER_CHARACTERFUNCTIONS_H_INCLUDED
27#define WATER_CHARACTERFUNCTIONS_H_INCLUDED
69 static bool isDigit (
char character)
noexcept;
74 static bool isLetter (
char character)
noexcept;
104 template <
typename CharPo
interType>
107 double result[3] = { 0 }, accumulator[2] = { 0 };
108 int exponentAdjustment[2] = { 0 }, exponentAccumulator[2] = { -1, -1 };
109 int exponent = 0, decPointIndex = 0, digit = 0;
110 int lastDigit = 0, numSignificantDigits = 0;
111 bool isNegative =
false, digitsFound =
false;
112 const int maxSignificantDigits = 15 + 2;
119 case '-': isNegative =
true;
120 case '+':
c = *++
text;
127 if ((
text[1] ==
'a' ||
text[1] ==
'A') && (
text[2] ==
'n' ||
text[2] ==
'N'))
128 return std::numeric_limits<double>::quiet_NaN();
133 if ((
text[1] ==
'n' ||
text[1] ==
'N') && (
text[2] ==
'f' ||
text[2] ==
'F'))
134 return std::numeric_limits<double>::infinity();
143 digit = (
int)
text.getAndAdvance() -
'0';
146 if (decPointIndex != 0)
147 exponentAdjustment[1]++;
149 if (numSignificantDigits == 0 && digit == 0)
152 if (++numSignificantDigits > maxSignificantDigits)
155 ++accumulator [decPointIndex];
156 else if (digit == 5 && (lastDigit & 1) != 0)
157 ++accumulator [decPointIndex];
159 if (decPointIndex > 0)
160 exponentAdjustment[1]--;
162 exponentAdjustment[0]++;
164 while (
text.isDigit())
167 if (decPointIndex == 0)
168 exponentAdjustment[0]++;
173 const double maxAccumulatorValue = (double) ((std::numeric_limits<unsigned int>::max() - 9) / 10);
174 if (accumulator [decPointIndex] > maxAccumulatorValue)
177 + accumulator [decPointIndex];
178 accumulator [decPointIndex] = 0;
179 exponentAccumulator [decPointIndex] = 0;
182 accumulator [decPointIndex] = accumulator[decPointIndex] * 10 + digit;
183 exponentAccumulator [decPointIndex]++;
186 else if (decPointIndex == 0 && *
text ==
'.')
191 if (numSignificantDigits > maxSignificantDigits)
193 while (
text.isDigit())
206 if (decPointIndex != 0)
210 if ((
c ==
'e' ||
c ==
'E') && digitsFound)
212 bool negativeExponent =
false;
216 case '-': negativeExponent =
true;
220 while (
text.isDigit())
221 exponent = (exponent * 10) + ((
int)
text.getAndAdvance() -
'0');
223 if (negativeExponent)
224 exponent = -exponent;
228 if (decPointIndex != 0)
231 return isNegative ? -
r :
r;
235 template <
typename CharPo
interType>
243 template <
typename IntType,
typename CharPo
interType>
247 CharPointerType
s (
text.findEndOfWhitespace());
249 const bool isNeg = *
s ==
'-';
257 if (
c >=
'0' &&
c <=
'9')
258 v =
v * 10 + (IntType) (
c -
'0');
263 return isNeg ? -
v :
v;
266 template <
typename ResultType>
269 template <
typename CharPo
interType>
270 static ResultType
parse (CharPointerType
t)
noexcept
274 while (!
t.isEmpty())
289 template <
typename CharPo
interType>
290 static size_t lengthUpTo (CharPointerType
text,
const size_t maxCharsToCount)
noexcept
294 while (len < maxCharsToCount &&
text.getAndAdvance() != 0)
302 template <
typename CharPo
interType>
307 while (
start < end &&
start.getAndAdvance() != 0)
314 template <
typename DestCharPo
interType,
typename SrcCharPo
interType>
315 static void copyAll (DestCharPointerType& dest, SrcCharPointerType src)
noexcept
325 template <
typename DestCharPo
interType,
typename SrcCharPo
interType>
326 static size_t copyWithDestByteLimit (DestCharPointerType& dest, SrcCharPointerType src,
size_t maxBytesToWrite)
noexcept
328 typename DestCharPointerType::CharType
const*
const startAddress = dest.getAddress();
329 ssize_t maxBytes = (ssize_t) maxBytesToWrite;
330 maxBytes -=
sizeof (
typename DestCharPointerType::CharType);
335 const size_t bytesNeeded = DestCharPointerType::getBytesRequiredFor (
c);
337 maxBytes -= bytesNeeded;
338 if (
c == 0 || maxBytes < 0)
347 +
sizeof (
typename DestCharPointerType::CharType);
352 template <
typename DestCharPo
interType,
typename SrcCharPo
interType>
353 static void copyWithCharLimit (DestCharPointerType& dest, SrcCharPointerType src,
int maxChars)
noexcept
355 while (--maxChars > 0)
370 if (
int diff =
static_cast<int> (char1) -
static_cast<int> (char2))
371 return diff < 0 ? -1 : 1;
377 template <
typename CharPo
interType1,
typename CharPo
interType2>
378 static int compare (CharPointerType1 s1, CharPointerType2 s2)
noexcept
395 template <
typename CharPo
interType1,
typename CharPo
interType2>
396 static int compareUpTo (CharPointerType1 s1, CharPointerType2 s2,
int maxChars)
noexcept
398 while (--maxChars >= 0)
419 template <
typename CharPo
interType1,
typename CharPo
interType2>
437 template <
typename CharPo
interType1,
typename CharPo
interType2>
440 while (--maxChars >= 0)
457 template <
typename CharPo
interType1,
typename CharPo
interType2>
458 static int indexOf (CharPointerType1 textToSearch,
const CharPointerType2 substringToLookFor)
noexcept
461 const int substringLength = (
int) substringToLookFor.length();
465 if (textToSearch.compareUpTo (substringToLookFor, substringLength) == 0)
468 if (textToSearch.getAndAdvance() == 0)
479 template <
typename CharPo
interType1,
typename CharPo
interType2>
480 static CharPointerType1
find (CharPointerType1 textToSearch,
const CharPointerType2 substringToLookFor)
noexcept
482 const int substringLength = (
int) substringToLookFor.length();
484 while (textToSearch.compareUpTo (substringToLookFor, substringLength) != 0
485 && ! textToSearch.isEmpty())
495 template <
typename CharPo
interType>
496 static CharPointerType
find (CharPointerType textToSearch,
const water_uchar charToLookFor)
noexcept
498 for (;; ++textToSearch)
502 if (
c == charToLookFor ||
c == 0)
513 template <
typename CharPo
interType1,
typename CharPo
interType2>
514 static int indexOfIgnoreCase (CharPointerType1 haystack,
const CharPointerType2 needle)
noexcept
517 const int needleLength = (
int) needle.length();
521 if (haystack.compareIgnoreCaseUpTo (needle, needleLength) == 0)
524 if (haystack.getAndAdvance() == 0)
534 template <
typename Type>
539 while (!
text.isEmpty())
541 if (
text.getAndAdvance() == charToFind)
554 template <
typename Type>
560 while (!
text.isEmpty())
562 if (
text.toLowerCase() == charToFind)
576 template <
typename Type>
579 while (
text.isWhitespace())
588 template <
typename Type,
typename BreakType>
593 while (!
text.isEmpty())
597 if (currentQuoteChar == 0 && breakCharacters.indexOf (
c) >= 0)
603 if (quoteCharacters.indexOf (
c) >= 0)
605 if (currentQuoteChar == 0)
606 currentQuoteChar =
c;
607 else if (currentQuoteChar ==
c)
608 currentQuoteChar = 0;
616 static double mulexp10 (
const double value,
int exponent)
noexcept;
Definition CharacterFunctions.h:50
static water_uchar toUpperCase(water_uchar character) noexcept
Definition CharacterFunctions.cpp:34
static int getHexDigitValue(water_uchar digit) noexcept
Definition CharacterFunctions.cpp:116
static int compareUpTo(CharPointerType1 s1, CharPointerType2 s2, int maxChars) noexcept
Definition CharacterFunctions.h:396
static bool isLetterOrDigit(char character) noexcept
Definition CharacterFunctions.cpp:94
static int indexOf(CharPointerType1 textToSearch, const CharPointerType2 substringToLookFor) noexcept
Definition CharacterFunctions.h:458
static bool isDigit(char character) noexcept
Definition CharacterFunctions.cpp:73
static bool isLetter(char character) noexcept
Definition CharacterFunctions.cpp:83
static bool isPrintable(char character) noexcept
Definition CharacterFunctions.cpp:106
static int compareIgnoreCase(water_uchar char1, water_uchar char2) noexcept
Definition CharacterFunctions.h:413
static int compareIgnoreCaseUpTo(CharPointerType1 s1, CharPointerType2 s2, int maxChars) noexcept
Definition CharacterFunctions.h:438
static int compare(CharPointerType1 s1, CharPointerType2 s2) noexcept
Definition CharacterFunctions.h:378
static double getDoubleValue(CharPointerType text) noexcept
Definition CharacterFunctions.h:236
static water_uchar toLowerCase(water_uchar character) noexcept
Definition CharacterFunctions.cpp:39
static double readDoubleValue(CharPointerType &text) noexcept
Definition CharacterFunctions.h:105
static int indexOfChar(Type text, const water_uchar charToFind) noexcept
Definition CharacterFunctions.h:535
static int indexOfIgnoreCase(CharPointerType1 haystack, const CharPointerType2 needle) noexcept
Definition CharacterFunctions.h:514
static CharPointerType1 find(CharPointerType1 textToSearch, const CharPointerType2 substringToLookFor) noexcept
Definition CharacterFunctions.h:480
static CharPointerType find(CharPointerType textToSearch, const water_uchar charToLookFor) noexcept
Definition CharacterFunctions.h:496
static bool isLowerCase(water_uchar character) noexcept
Definition CharacterFunctions.cpp:53
static int compare(water_uchar char1, water_uchar char2) noexcept
Definition CharacterFunctions.h:368
static bool isUpperCase(water_uchar character) noexcept
Definition CharacterFunctions.cpp:44
static void copyAll(DestCharPointerType &dest, SrcCharPointerType src) noexcept
Definition CharacterFunctions.h:315
static int indexOfCharIgnoreCase(Type text, water_uchar charToFind) noexcept
Definition CharacterFunctions.h:555
static void copyWithCharLimit(DestCharPointerType &dest, SrcCharPointerType src, int maxChars) noexcept
Definition CharacterFunctions.h:353
static size_t lengthUpTo(CharPointerType start, const CharPointerType end) noexcept
Definition CharacterFunctions.h:303
static Type findEndOfToken(Type text, const BreakType breakCharacters, const Type quoteCharacters)
Definition CharacterFunctions.h:589
static int compareIgnoreCase(CharPointerType1 s1, CharPointerType2 s2) noexcept
Definition CharacterFunctions.h:420
static Type findEndOfWhitespace(Type text) noexcept
Definition CharacterFunctions.h:577
static double mulexp10(const double value, int exponent) noexcept
Definition CharacterFunctions.cpp:133
static size_t lengthUpTo(CharPointerType text, const size_t maxCharsToCount) noexcept
Definition CharacterFunctions.h:290
static bool isWhitespace(char character) noexcept
Definition CharacterFunctions.cpp:63
static water_uchar getUnicodeCharFromWindows1252Codepage(uint8 windows1252Char) noexcept
Definition CharacterFunctions.cpp:161
static size_t copyWithDestByteLimit(DestCharPointerType &dest, SrcCharPointerType src, size_t maxBytesToWrite) noexcept
Definition CharacterFunctions.h:326
static IntType getIntValue(const CharPointerType text) noexcept
Definition CharacterFunctions.h:244
struct huft * t
Definition inflate.c:943
unsigned v[N_MAX]
Definition inflate.c:1584
register unsigned i
Definition inflate.c:1575
unsigned s
Definition inflate.c:1555
static PuglViewHint int value
Definition pugl.h:1708
virtual ASIOError start()=0
Definition AudioSampleBuffer.h:33
int getAddressDifference(Type1 *pointer1, Type2 *pointer2) noexcept
Definition Memory.h:62
unsigned int uint32
Definition water.h:98
unsigned char uint8
Definition water.h:90
uint32 water_uchar
Definition CharacterFunctions.h:38
static bool diff(const std::string fn1, const std::string fn2)
Definition playertest.cpp:161
Definition CharacterFunctions.h:268
static ResultType parse(CharPointerType t) noexcept
Definition CharacterFunctions.h:270
const char * text
Definition swell-functions.h:167
return c
Definition crypt.c:175
int r
Definition crypt.c:458
int result
Definition process.c:1455
typedef int(UZ_EXP MsgFn)()