From 531227a482e3f66f2f3d3dc196d946df8a28391f Mon Sep 17 00:00:00 2001 From: Thilo Graf Date: Thu, 28 Mar 2019 11:28:47 +0100 Subject: [PATCH] helpers: add isDigitWord() function returns true if all chars of string parameter are digits --- src/system/helpers.cpp | 9 +++++++++ src/system/helpers.h | 2 ++ 2 files changed, 11 insertions(+) diff --git a/src/system/helpers.cpp b/src/system/helpers.cpp index a9d4e88df..01b1add18 100644 --- a/src/system/helpers.cpp +++ b/src/system/helpers.cpp @@ -1742,4 +1742,13 @@ std::string encodeUrl(std::string txt) return txt; } +bool isDigitWord(std::string str) +{ + for (size_t i=0; i < str.size(); i++) + if (!isdigit(str[i])) + return false; + + return true; +} + // diff --git a/src/system/helpers.h b/src/system/helpers.h index d51b42ee8..31029f314 100644 --- a/src/system/helpers.h +++ b/src/system/helpers.h @@ -182,5 +182,7 @@ std::string decodeUrl(std::string url); bool getUrl(std::string &url, std::string &answer, const std::string userAgent = " ", unsigned int timeout = 60); bool downloadUrl(std::string url, std::string file, const std::string userAgent = " ", unsigned int timeout = 60); +bool isDigitWord(std::string str); + // #endif