JsonRemedy.Layer3.BinaryProcessors (JsonRemedy v0.1.11)

View Source

Binary pattern matching optimization functions for Layer 3 syntax normalization.

Contains optimized binary processing functions that eliminate String.at/2 calls for maximum performance.

Summary

Functions

Analyze a consumed number string and normalize it appropriately.

Check if there's more content after an identifier that should be part of an unquoted value. This handles cases like "Weiss Savage" where there are spaces between words.

Binary pattern matching for identifier consumption - UTF-8 safe.

Binary pattern matching for number consumption (legacy - kept for compatibility).

Enhanced number consumption that handles edge cases.

Consume an unquoted value until the next JSON delimiter. This handles unquoted string values that may contain spaces.

Determine expecting state after closing delimiters.

Determine next expecting state after simple transitions.

Functions

analyze_and_normalize_number(number_str, pos)

@spec analyze_and_normalize_number(String.t(), non_neg_integer()) ::
  {String.t(), list()}

Analyze a consumed number string and normalize it appropriately.

Returns {normalized_value, repairs} where normalized_value is either:

  • A valid number string that JSON can parse
  • A quoted string for invalid number patterns

check_for_multi_word_value(remaining_binary, initial_word)

@spec check_for_multi_word_value(binary(), String.t()) ::
  {String.t(), binary(), non_neg_integer()}

Check if there's more content after an identifier that should be part of an unquoted value. This handles cases like "Weiss Savage" where there are spaces between words.

consume_identifier_binary_simple(binary)

@spec consume_identifier_binary_simple(binary()) ::
  {String.t(), binary(), non_neg_integer()}

Binary pattern matching for identifier consumption - UTF-8 safe.

consume_number_binary_simple(binary)

@spec consume_number_binary_simple(binary()) ::
  {String.t(), binary(), non_neg_integer()}

Binary pattern matching for number consumption (legacy - kept for compatibility).

consume_number_with_edge_cases(binary)

@spec consume_number_with_edge_cases(binary()) ::
  {String.t(), binary(), non_neg_integer()}

Enhanced number consumption that handles edge cases.

Consumes characters that could be part of a number, including:

  • Standard number chars: digits, ., -, +, e, E
  • Edge case chars: / (fractions), multiple - (ranges), text (hybrids), unicode
  • Currency symbols: $, , £, ¥ (at start)
  • Commas: , (when already consuming digits - for European decimals or thousands)

Returns the raw consumed string which will be analyzed separately.

consume_unquoted_value_binary_simple(binary, acc \\ <<>>, count \\ 0)

@spec consume_unquoted_value_binary_simple(binary(), binary(), non_neg_integer()) ::
  {String.t(), binary(), non_neg_integer()}

Consume an unquoted value until the next JSON delimiter. This handles unquoted string values that may contain spaces.

determine_expecting_after_close_simple(arg1)

@spec determine_expecting_after_close_simple(list()) :: atom()

Determine expecting state after closing delimiters.

determine_next_expecting_simple(expecting, stack)

@spec determine_next_expecting_simple(atom(), list()) :: atom()

Determine next expecting state after simple transitions.

process_identifier_binary_simple(binary, result_iolist, repairs, in_string, escape_next, quote, stack, expecting, pos)

@spec process_identifier_binary_simple(
  binary(),
  iolist(),
  list(),
  boolean(),
  boolean(),
  String.t() | nil,
  list(),
  atom(),
  non_neg_integer()
) ::
  {binary(), iolist(), list(), boolean(), boolean(), String.t() | nil, list(),
   atom(), non_neg_integer()}

Process identifiers with binary pattern matching.

process_number_binary_simple(binary, result_iolist, repairs, in_string, escape_next, quote, stack, expecting, pos)

@spec process_number_binary_simple(
  binary(),
  iolist(),
  list(),
  boolean(),
  boolean(),
  String.t() | nil,
  list(),
  atom(),
  non_neg_integer()
) ::
  {binary(), iolist(), list(), boolean(), boolean(), String.t() | nil, list(),
   atom(), non_neg_integer()}

Process numbers with binary pattern matching and edge case handling.

Handles:

  • Fractions: 1/3"1/3"
  • Ranges: 10-20"10-20"
  • Invalid decimals: 1.1.1"1.1.1"
  • Leading decimals: .250.25
  • Text-number hybrids: 1notanumber"1notanumber"
  • Trailing operators: 1e, 1. → normalize
  • Unicode/currency: 123€"123€"