This is probably the most similar way to do it to the code you posted. Note, don’t use operator[] to access the characters because it will be slow if your string is stored in utf8 internally.
bool is_number(const juce::String& s)
{
auto t = s.getCharPointer();
while (*t)
{
if (! t.isDigit())
return false;
t++;
}
return true;
}
String text { "123.45,67" };
const auto charptr = text.getCharPointer();
auto ptr = charptr;
auto value = CharacterFunctions::readDoubleValue (ptr);
DBG ("Number: " << value << ((ptr - charptr == text.getNumBytesAsUTF8()) ? " ok" : " not ok"));
Explanation: the ptr is advanced through the string, so it will point either to the \0 or to the character, that doesn’t fit into the number. Hence the difference of the ptr to the initial charptr should be the length of the string, otherwise something went wrong…