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.

152 lines
4.3KB

  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. //==============================================================================
  19. #if JUCE_MSVC
  20. #pragma warning (push)
  21. #pragma warning (disable: 4514 4996)
  22. #endif
  23. juce_wchar CharacterFunctions::toUpperCase (const juce_wchar character) noexcept
  24. {
  25. return towupper ((wchar_t) character);
  26. }
  27. juce_wchar CharacterFunctions::toLowerCase (const juce_wchar character) noexcept
  28. {
  29. return towlower ((wchar_t) character);
  30. }
  31. bool CharacterFunctions::isUpperCase (const juce_wchar character) noexcept
  32. {
  33. #if JUCE_WINDOWS
  34. return iswupper ((wchar_t) character) != 0;
  35. #else
  36. return toLowerCase (character) != character;
  37. #endif
  38. }
  39. bool CharacterFunctions::isLowerCase (const juce_wchar character) noexcept
  40. {
  41. #if JUCE_WINDOWS
  42. return iswlower ((wchar_t) character) != 0;
  43. #else
  44. return toUpperCase (character) != character;
  45. #endif
  46. }
  47. #if JUCE_MSVC
  48. #pragma warning (pop)
  49. #endif
  50. //==============================================================================
  51. bool CharacterFunctions::isWhitespace (const char character) noexcept
  52. {
  53. return character == ' ' || (character <= 13 && character >= 9);
  54. }
  55. bool CharacterFunctions::isWhitespace (const juce_wchar character) noexcept
  56. {
  57. return iswspace ((wchar_t) character) != 0;
  58. }
  59. bool CharacterFunctions::isDigit (const char character) noexcept
  60. {
  61. return (character >= '0' && character <= '9');
  62. }
  63. bool CharacterFunctions::isDigit (const juce_wchar character) noexcept
  64. {
  65. return iswdigit ((wchar_t) character) != 0;
  66. }
  67. bool CharacterFunctions::isLetter (const char character) noexcept
  68. {
  69. return (character >= 'a' && character <= 'z')
  70. || (character >= 'A' && character <= 'Z');
  71. }
  72. bool CharacterFunctions::isLetter (const juce_wchar character) noexcept
  73. {
  74. return iswalpha ((wchar_t) character) != 0;
  75. }
  76. bool CharacterFunctions::isLetterOrDigit (const char character) noexcept
  77. {
  78. return (character >= 'a' && character <= 'z')
  79. || (character >= 'A' && character <= 'Z')
  80. || (character >= '0' && character <= '9');
  81. }
  82. bool CharacterFunctions::isLetterOrDigit (const juce_wchar character) noexcept
  83. {
  84. return iswalnum ((wchar_t) character) != 0;
  85. }
  86. int CharacterFunctions::getHexDigitValue (const juce_wchar digit) noexcept
  87. {
  88. unsigned int d = digit - '0';
  89. if (d < (unsigned int) 10)
  90. return (int) d;
  91. d += (unsigned int) ('0' - 'a');
  92. if (d < (unsigned int) 6)
  93. return (int) d + 10;
  94. d += (unsigned int) ('a' - 'A');
  95. if (d < (unsigned int) 6)
  96. return (int) d + 10;
  97. return -1;
  98. }
  99. double CharacterFunctions::mulexp10 (const double value, int exponent) noexcept
  100. {
  101. if (exponent == 0)
  102. return value;
  103. if (value == 0)
  104. return 0;
  105. const bool negative = (exponent < 0);
  106. if (negative)
  107. exponent = -exponent;
  108. double result = 1.0, power = 10.0;
  109. for (int bit = 1; exponent != 0; bit <<= 1)
  110. {
  111. if ((exponent & bit) != 0)
  112. {
  113. exponent ^= bit;
  114. result *= power;
  115. if (exponent == 0)
  116. break;
  117. }
  118. power *= power;
  119. }
  120. return negative ? (value / result) : (value * result);
  121. }