Skip to content

add the is_numeric method - #50

Merged
FFMG merged 3 commits into
FFMG:mainfrom
useroutofbound:add-new-func
Oct 15, 2026
Merged

FFMG merged 3 commits into
FFMG:mainfrom
useroutofbound:add-new-func

Conversation

@useroutofbound

@useroutofbound useroutofbound commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Add is_numeric() to TJValue

Closes #49

Summary

Adds a virtual is_numeric(bool strict = false) const method to TJValue so any JSON value can report whether it is numeric. In non-strict mode, strings containing a valid number also count as numeric.

Changes

src/TinyJSON.h

  • Added virtual bool is_numeric(bool strict = false) const; to TJValue.

src/TinyJSON.cpp

Class Behavior
TJValue (base) Returns false
TJValueNumber Always returns true
TJValueString Returns false if strict; otherwise scans characters to validate a number (optional sign, decimal point, scientific notation)
TJValueObject, TJValueArray, TJValueBoolean, TJValueNull, TJValueComment Return false

Behavior

Input strict = false strict = true
Number 42 true true
String "42" true false
String "-3.14e2" true false
String "abc" false false
String "" false false
Boolean / null / array / object false false

Notes

  • Non-breaking: strict defaults to false and the method is purely additive.
  • Strict mode only accepts real TJValueNumber instances.

@useroutofbound

Copy link
Copy Markdown
Contributor Author

I have fixed the build issues by adding the override specifiers to the
is_numeric declarations in all derived classes within src/TinyJSON.h.

@useroutofbound useroutofbound left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have fixed the build issues by adding the override specifiers to the
is_numeric declarations in all derived classes within src/TinyJSON.h.

@FFMG

FFMG commented Sep 24, 2026

Copy link
Copy Markdown
Owner

Thanks for this PR, but you will need to add some tests as well please.

Especially for the TJValueString but for all cases really.

@useroutofbound

Copy link
Copy Markdown
Contributor Author

Added new test file and also fixed the unused parameter warning

@FFMG
FFMG merged commit 2a91c7e into FFMG:main Oct 15, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a generic is_numeric() function

2 participants