diff --git a/include/Utils/StringUtils.h b/include/Utils/StringUtils.h index 2bf412cc..e98a8f76 100644 --- a/include/Utils/StringUtils.h +++ b/include/Utils/StringUtils.h @@ -26,7 +26,9 @@ size_t itemsCount2(String str, const String& separator); size_t itemsCount(String& str, const char* delim); -boolean isDigitStr(const String&); +boolean isDigitStr(const String& str); + +boolean isDigitDotCommaStr(const String& str); String prettyBytes(size_t size); diff --git a/src/Tests.cpp b/src/Tests.cpp index 0ce15233..b274c711 100644 --- a/src/Tests.cpp +++ b/src/Tests.cpp @@ -8,6 +8,8 @@ void testsPerform() { Serial.println("====some tests section===="); + //Serial.println(isDigitDotCommaStr("-12552.5555")); + //String str = "Geeks for Geeks "; // //Serial.println(itemsCount2(str, " ")); diff --git a/src/Utils/StringUtils.cpp b/src/Utils/StringUtils.cpp index 08ec5fa9..11e110bd 100644 --- a/src/Utils/StringUtils.cpp +++ b/src/Utils/StringUtils.cpp @@ -114,6 +114,16 @@ boolean isDigitStr(const String& str) { return str.length(); } +boolean isDigitDotCommaStr(const String& str) { + for (size_t i = 0; i < str.length(); i++) { + char latter = str.charAt(i); + if (!isDigit(latter) && latter != '.' && latter != '-') { + return false; + } + } + return true; +} + String prettyBytes(size_t size) { if (size < 1024) return String(size) + "b";