MCPcopy Create free account
hub / github.com/RomanKubiak/ctrlr / reduceLengthOfFloatString

Function reduceLengthOfFloatString

JUCE/modules/juce_core/text/juce_String.cpp:2199–2268  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2197//==============================================================================
2198
2199static String reduceLengthOfFloatString (const String& input)
2200{
2201 const auto start = input.getCharPointer();
2202 const auto end = start + (int) input.length();
2203 auto trimStart = end;
2204 auto trimEnd = trimStart;
2205 auto exponentTrimStart = end;
2206 auto exponentTrimEnd = exponentTrimStart;
2207
2208 decltype (*start) currentChar = '\0';
2209
2210 for (auto c = end - 1; c > start; --c)
2211 {
2212 currentChar = *c;
2213
2214 if (currentChar == '0' && c + 1 == trimStart)
2215 {
2216 --trimStart;
2217 }
2218 else if (currentChar == '.')
2219 {
2220 if (trimStart == c + 1 && trimStart != end && *trimStart == '0')
2221 ++trimStart;
2222
2223 break;
2224 }
2225 else if (currentChar == 'e' || currentChar == 'E')
2226 {
2227 auto cNext = c + 1;
2228
2229 if (cNext != end)
2230 {
2231 if (*cNext == '-')
2232 ++cNext;
2233
2234 exponentTrimStart = cNext;
2235
2236 if (cNext != end && *cNext == '+')
2237 ++cNext;
2238
2239 exponentTrimEnd = cNext;
2240 }
2241
2242 while (cNext != end && *cNext++ == '0')
2243 exponentTrimEnd = cNext;
2244
2245 if (exponentTrimEnd == end)
2246 exponentTrimStart = c;
2247
2248 trimStart = c;
2249 trimEnd = trimStart;
2250 }
2251 }
2252
2253 if ((trimStart != trimEnd && currentChar == '.') || exponentTrimStart != exponentTrimEnd)
2254 {
2255 if (trimStart == trimEnd)
2256 return String (start, exponentTrimStart) + String (exponentTrimEnd, end);

Callers 2

serialiseDoubleFunction · 0.85
runTestMethod · 0.85

Calls 2

StringFunction · 0.70
lengthMethod · 0.45

Tested by

no test coverage detected