upgrade to JUCE 5.4.3. Remove (probably) unused JUCE modules. Remove VST2 target (it's been end-of-life'd by Steinberg and by JUCE)
This commit is contained in:
@ -153,11 +153,11 @@ public:
|
||||
toUTF32() methods let you access the string's content in any of the other formats.
|
||||
*/
|
||||
#if (JUCE_STRING_UTF_TYPE == 32)
|
||||
typedef CharPointer_UTF32 CharPointerType;
|
||||
using CharPointerType = CharPointer_UTF32;
|
||||
#elif (JUCE_STRING_UTF_TYPE == 16)
|
||||
typedef CharPointer_UTF16 CharPointerType;
|
||||
using CharPointerType = CharPointer_UTF16;
|
||||
#elif (DOXYGEN || JUCE_STRING_UTF_TYPE == 8)
|
||||
typedef CharPointer_UTF8 CharPointerType;
|
||||
using CharPointerType = CharPointer_UTF8;
|
||||
#else
|
||||
#error "You must set the value of JUCE_STRING_UTF_TYPE to be either 8, 16, or 32!"
|
||||
#endif
|
||||
@ -962,21 +962,26 @@ public:
|
||||
|
||||
/** Creates a string representing this floating-point number.
|
||||
@param floatValue the value to convert to a string
|
||||
@param numberOfDecimalPlaces if this is > 0, it will format the number using that many
|
||||
decimal places, and will not use exponent notation. If 0 or
|
||||
less, it will use exponent notation if necessary.
|
||||
@param numberOfDecimalPlaces if this is > 0 the number will be formatted using that many
|
||||
decimal places, adding trailing zeros as required. If 0 or
|
||||
less the number will be formatted using the C++ standard
|
||||
library default format, which uses scientific notation for
|
||||
large and small numbers.
|
||||
@param useScientificNotation if the number should be formatted using scientific notation
|
||||
@see getDoubleValue, getIntValue
|
||||
*/
|
||||
String (float floatValue, int numberOfDecimalPlaces);
|
||||
String (float floatValue, int numberOfDecimalPlaces, bool useScientificNotation = false);
|
||||
|
||||
/** Creates a string representing this floating-point number.
|
||||
@param doubleValue the value to convert to a string
|
||||
@param numberOfDecimalPlaces if this is > 0, it will format the number using that many
|
||||
decimal places, and will not use exponent notation. If 0 or
|
||||
less, it will use exponent notation if necessary.
|
||||
decimal places, adding trailing zeros as required, and
|
||||
will not use exponent notation. If 0 or less, it will use
|
||||
exponent notation if necessary.
|
||||
@param useScientificNotation if the number should be formatted using scientific notation
|
||||
@see getFloatValue, getIntValue
|
||||
*/
|
||||
String (double doubleValue, int numberOfDecimalPlaces);
|
||||
String (double doubleValue, int numberOfDecimalPlaces, bool useScientificNotation = false);
|
||||
|
||||
// Automatically creating a String from a bool opens up lots of nasty type conversion edge cases.
|
||||
// If you want a String representation of a bool you can cast the bool to an int first.
|
||||
@ -1056,6 +1061,131 @@ public:
|
||||
*/
|
||||
static String toHexString (const void* data, int size, int groupSize = 1);
|
||||
|
||||
/** Returns a string containing a decimal with a set number of significant figures.
|
||||
|
||||
@param number the intput number
|
||||
@param numberOfSignificantFigures the number of significant figures to use
|
||||
*/
|
||||
template <typename DecimalType>
|
||||
static String toDecimalStringWithSignificantFigures (DecimalType number, int numberOfSignificantFigures)
|
||||
{
|
||||
jassert (numberOfSignificantFigures > 0);
|
||||
|
||||
if (number == 0)
|
||||
{
|
||||
if (numberOfSignificantFigures > 1)
|
||||
{
|
||||
String result ("0.0");
|
||||
|
||||
for (int i = 2; i < numberOfSignificantFigures; ++i)
|
||||
result += "0";
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
return "0";
|
||||
}
|
||||
|
||||
auto numDigitsBeforePoint = (int) std::ceil (std::log10 (number < 0 ? -number : number));
|
||||
|
||||
#if JUCE_PROJUCER_LIVE_BUILD
|
||||
auto doubleNumber = (double) number;
|
||||
constexpr int bufferSize = 311;
|
||||
char buffer[bufferSize];
|
||||
auto* ptr = &(buffer[0]);
|
||||
auto* const safeEnd = ptr + (bufferSize - 1);
|
||||
auto numSigFigsParsed = 0;
|
||||
|
||||
auto writeToBuffer = [safeEnd] (char* destination, char data)
|
||||
{
|
||||
*destination++ = data;
|
||||
|
||||
if (destination == safeEnd)
|
||||
{
|
||||
*destination = '\0';
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
auto truncateOrRound = [numberOfSignificantFigures] (double fractional, int sigFigsParsed)
|
||||
{
|
||||
return (sigFigsParsed == numberOfSignificantFigures - 1) ? (int) std::round (fractional)
|
||||
: (int) fractional;
|
||||
};
|
||||
|
||||
if (doubleNumber < 0)
|
||||
{
|
||||
doubleNumber *= -1;
|
||||
*ptr++ = '-';
|
||||
}
|
||||
|
||||
if (numDigitsBeforePoint > 0)
|
||||
{
|
||||
doubleNumber /= std::pow (10.0, numDigitsBeforePoint);
|
||||
|
||||
while (numDigitsBeforePoint-- > 0)
|
||||
{
|
||||
if (numSigFigsParsed == numberOfSignificantFigures)
|
||||
{
|
||||
if (writeToBuffer (ptr++, '0'))
|
||||
return buffer;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
doubleNumber *= 10;
|
||||
auto digit = truncateOrRound (doubleNumber, numSigFigsParsed);
|
||||
|
||||
if (writeToBuffer (ptr++, (char) ('0' + digit)))
|
||||
return buffer;
|
||||
|
||||
++numSigFigsParsed;
|
||||
doubleNumber -= digit;
|
||||
}
|
||||
|
||||
if (numSigFigsParsed == numberOfSignificantFigures)
|
||||
{
|
||||
*ptr++ = '\0';
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
*ptr++ = '0';
|
||||
}
|
||||
|
||||
if (writeToBuffer (ptr++, '.'))
|
||||
return buffer;
|
||||
|
||||
while (numSigFigsParsed < numberOfSignificantFigures)
|
||||
{
|
||||
doubleNumber *= 10;
|
||||
auto digit = truncateOrRound (doubleNumber, numSigFigsParsed);
|
||||
|
||||
if (writeToBuffer (ptr++, (char) ('0' + digit)))
|
||||
return buffer;
|
||||
|
||||
if (numSigFigsParsed != 0 || digit != 0)
|
||||
++numSigFigsParsed;
|
||||
|
||||
doubleNumber -= digit;
|
||||
}
|
||||
|
||||
*ptr++ = '\0';
|
||||
return buffer;
|
||||
#else
|
||||
auto shift = numberOfSignificantFigures - numDigitsBeforePoint;
|
||||
auto factor = std::pow (10.0, shift);
|
||||
auto rounded = std::round (number * factor) / factor;
|
||||
|
||||
std::stringstream ss;
|
||||
ss << std::fixed << std::setprecision (std::max (shift, 0)) << rounded;
|
||||
return ss.str();
|
||||
#endif
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
/** Returns the character pointer currently being used to store this string.
|
||||
|
||||
@ -1278,7 +1408,7 @@ private:
|
||||
static String createHex (uint64);
|
||||
|
||||
template <typename Type>
|
||||
static String createHex (Type n) { return createHex (static_cast<typename TypeHelpers::UnsignedTypeWithSize<sizeof (n)>::type> (n)); }
|
||||
static String createHex (Type n) { return createHex (static_cast<typename TypeHelpers::UnsignedTypeWithSize<(int) sizeof (n)>::type> (n)); }
|
||||
};
|
||||
|
||||
//==============================================================================
|
||||
|
Reference in New Issue
Block a user