The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

180 lines
5.5KB

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