From 401564a7781d6ef8d36b2cc231e4ef64bea09ca0 Mon Sep 17 00:00:00 2001 From: Dmitry Borisenko <49808844+DmitryBorisenko33@users.noreply.github.com> Date: Sat, 2 Jan 2021 13:07:45 +0100 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=B4=D1=80=D0=BE=D0=B1=D0=B5=D0=B9=20=D0=B8=20=D0=BE?= =?UTF-8?q?=D1=82=D1=80=D0=B8=D1=86=D0=B0=D1=82=D0=B5=D0=BB=D1=8C=D0=BD?= =?UTF-8?q?=D1=8B=D1=85=20=D1=87=D0=B8=D1=81=D0=B5=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/Utils/StringUtils.h | 4 +++- src/Tests.cpp | 2 ++ src/Utils/StringUtils.cpp | 10 ++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) 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";