Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

173 lines
5.2KB

  1. /*
  2. ==============================================================================
  3. This file is part of the Water library.
  4. Copyright (c) 2016 ROLI Ltd.
  5. Copyright (C) 2017 Filipe Coelho <falktx@falktx.com>
  6. Permission is granted to use this software under the terms of the ISC license
  7. http://www.isc.org/downloads/software-support-policy/isc-license/
  8. Permission to use, copy, modify, and/or distribute this software for any
  9. purpose with or without fee is hereby granted, provided that the above
  10. copyright notice and this permission notice appear in all copies.
  11. THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
  12. TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  13. FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
  14. OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  15. USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  16. TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  17. OF THIS SOFTWARE.
  18. ==============================================================================
  19. */
  20. #include "CharacterFunctions.h"
  21. namespace water {
  22. //==============================================================================
  23. juce_wchar CharacterFunctions::toUpperCase (const juce_wchar character) noexcept
  24. {
  25. return (juce_wchar) towupper ((wint_t) character);
  26. }
  27. juce_wchar CharacterFunctions::toLowerCase (const juce_wchar character) noexcept
  28. {
  29. return (juce_wchar) towlower ((wint_t) character);
  30. }
  31. bool CharacterFunctions::isUpperCase (const juce_wchar character) noexcept
  32. {
  33. #ifdef CARLA_OS_WIN
  34. return iswupper ((wint_t) character) != 0;
  35. #else
  36. return toLowerCase (character) != character;
  37. #endif
  38. }
  39. bool CharacterFunctions::isLowerCase (const juce_wchar character) noexcept
  40. {
  41. #ifdef CARLA_OS_WIN
  42. return iswlower ((wint_t) character) != 0;
  43. #else
  44. return toUpperCase (character) != character;
  45. #endif
  46. }
  47. //==============================================================================
  48. bool CharacterFunctions::isWhitespace (const char character) noexcept
  49. {
  50. return character == ' ' || (character <= 13 && character >= 9);
  51. }
  52. bool CharacterFunctions::isWhitespace (const juce_wchar character) noexcept
  53. {
  54. return iswspace ((wint_t) character) != 0;
  55. }
  56. bool CharacterFunctions::isDigit (const char character) noexcept
  57. {
  58. return (character >= '0' && character <= '9');
  59. }
  60. bool CharacterFunctions::isDigit (const juce_wchar character) noexcept
  61. {
  62. return iswdigit ((wint_t) character) != 0;
  63. }
  64. bool CharacterFunctions::isLetter (const char character) noexcept
  65. {
  66. return (character >= 'a' && character <= 'z')
  67. || (character >= 'A' && character <= 'Z');
  68. }
  69. bool CharacterFunctions::isLetter (const juce_wchar character) noexcept
  70. {
  71. return iswalpha ((wint_t) character) != 0;
  72. }
  73. bool CharacterFunctions::isLetterOrDigit (const char character) noexcept
  74. {
  75. return (character >= 'a' && character <= 'z')
  76. || (character >= 'A' && character <= 'Z')
  77. || (character >= '0' && character <= '9');
  78. }
  79. bool CharacterFunctions::isLetterOrDigit (const juce_wchar character) noexcept
  80. {
  81. return iswalnum ((wint_t) character) != 0;
  82. }
  83. bool CharacterFunctions::isPrintable (const char character) noexcept
  84. {
  85. return (character >= ' ' && character <= '~');
  86. }
  87. bool CharacterFunctions::isPrintable (const juce_wchar character) noexcept
  88. {
  89. return iswprint ((wint_t) character) != 0;
  90. }
  91. int CharacterFunctions::getHexDigitValue (const juce_wchar digit) noexcept
  92. {
  93. unsigned int d = (unsigned int) digit - '0';
  94. if (d < (unsigned int) 10)
  95. return (int) d;
  96. d += (unsigned int) ('0' - 'a');
  97. if (d < (unsigned int) 6)
  98. return (int) d + 10;
  99. d += (unsigned int) ('a' - 'A');
  100. if (d < (unsigned int) 6)
  101. return (int) d + 10;
  102. return -1;
  103. }
  104. double CharacterFunctions::mulexp10 (const double value, int exponent) noexcept
  105. {
  106. if (exponent == 0)
  107. return value;
  108. if (value == 0)
  109. return 0;
  110. const bool negative = (exponent < 0);
  111. if (negative)
  112. exponent = -exponent;
  113. double result = 1.0, power = 10.0;
  114. for (int bit = 1; exponent != 0; bit <<= 1)
  115. {
  116. if ((exponent & bit) != 0)
  117. {
  118. exponent ^= bit;
  119. result *= power;
  120. if (exponent == 0)
  121. break;
  122. }
  123. power *= power;
  124. }
  125. return negative ? (value / result) : (value * result);
  126. }
  127. juce_wchar CharacterFunctions::getUnicodeCharFromWindows1252Codepage (const uint8 c) noexcept
  128. {
  129. if (c < 0x80 || c >= 0xa0)
  130. return (juce_wchar) c;
  131. static const uint16 lookup[] = { 0x20AC, 0x0007, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
  132. 0x02C6, 0x2030, 0x0160, 0x2039, 0x0152, 0x0007, 0x017D, 0x0007,
  133. 0x0007, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
  134. 0x02DC, 0x2122, 0x0161, 0x203A, 0x0153, 0x0007, 0x017E, 0x0178 };
  135. return (juce_wchar) lookup[c - 0x80];
  136. }
  137. }