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.

172 lines
5.0KB

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