File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -246,6 +246,24 @@ namespace StormByte::String {
246246 return out;
247247 }
248248
249+ bool IsInteger (const std::string& str) noexcept {
250+ if (str.empty ()) return false ;
251+
252+ size_t start = 0 ;
253+ if (str[0 ] == ' -' || str[0 ] == ' +' ) {
254+ if (str.size () == 1 ) return false ; // Only sign, no digits
255+ start = 1 ;
256+ }
257+
258+ for (size_t i = start; i < str.size (); ++i) {
259+ if (!std::isdigit (static_cast <unsigned char >(str[i]))) {
260+ return false ;
261+ }
262+ }
263+
264+ return true ;
265+ }
266+
249267 // Explicit instantiations for `HumanReadable` (ordered by category).
250268 // Note: `wchar_t`, `char16_t`, and `char32_t` are excluded because they are not
251269 // streamed to `std::ostringstream` on many standard library implementations.
Original file line number Diff line number Diff line change @@ -179,4 +179,14 @@ namespace StormByte::String {
179179 * @return The string with all whitespace characters removed.
180180 */
181181 STORMBYTE_PUBLIC std::string RemoveWhitespace (const std::string& str) noexcept ;
182+
183+ /* *
184+ * @brief Checks if a string represents a valid integer.
185+ *
186+ * This function determines whether the given string can be interpreted as an integer.
187+ *
188+ * @param str The string to check.
189+ * @return `true` if the string represents an integer, `false` otherwise.
190+ */
191+ STORMBYTE_PUBLIC bool IsInteger (const std::string& str) noexcept ;
182192}
You can’t perform that action at this time.
0 commit comments