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.

163 lines
4.4KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #if ! JUCE_ANDROID
  19. #include <cwctype>
  20. #endif
  21. #include <cctype>
  22. BEGIN_JUCE_NAMESPACE
  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 towupper ((wchar_t) character);
  31. }
  32. juce_wchar CharacterFunctions::toLowerCase (const juce_wchar character) noexcept
  33. {
  34. return towlower ((wchar_t) character);
  35. }
  36. bool CharacterFunctions::isUpperCase (const juce_wchar character) noexcept
  37. {
  38. #if JUCE_WINDOWS
  39. return iswupper ((wchar_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 ((wchar_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 ((wchar_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 ((wchar_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 ((wchar_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 ((wchar_t) character) != 0;
  90. }
  91. int CharacterFunctions::getHexDigitValue (const juce_wchar digit) noexcept
  92. {
  93. unsigned int d = 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. END_JUCE_NAMESPACE