parseJsonNumber

fnbool parseJsonNumber(const(char)[] lexeme, out var result, out string errorMsg, bool preferSigned = true) @safe

Parse a JSON number literal and return the appropriate var type.

This function takes a number lexeme and parses it into the most appropriate numeric type according to JSON semantics:

  • If the number is integral and fits in a long, use var.Type.LONG.
  • If the number is integral, non-negative, and fits in ulong but not long, use var.Type.ULONG.
  • Otherwise (decimals, exponents, overflow), use var.Type.DOUBLE.
With preferSigned = false, non-negative integers that fit are reported as var.Type.ULONG instead of var.Type.LONG (negative integers remain LONG; there is no unsigned representation).

Parameters

lexemeThe number literal lexeme from the lexer.
resultOutput parameter for the parsed value.
errorMsgOutput parameter for error message on failure.
preferSignedWhen true, prefer signed integers when value fits both; when false, prefer ulong for non-negative integers.

Returns

true on success, false on error (with errorMsg set).