decodeValueFromLines function

Object? decodeValueFromLines(
  1. LineCursor cursor,
  2. ResolvedDecodeOptions options
)

Decodes a Toon-formatted string to JsonValue

Implementation

Object? decodeValueFromLines(LineCursor cursor, ResolvedDecodeOptions options) {
  final first = cursor.peek();
  if (first == null) {
    throw StateError('No content to decode');
  }

  // Check for root array
  if (isArrayHeaderAfterHyphen(first.content)) {
    final headerInfo = parseArrayHeaderLine(first.content, defaultDelimiters);
    if (headerInfo != null) {
      cursor.advance(); // Move past the header line
      return decodeArrayFromHeader(
          headerInfo.header, headerInfo.inlineValues, cursor, 0, options);
    }
  }

  // Check for single primitive value
  if (cursor.length == 1 && !_isKeyValueLine(first)) {
    return parsePrimitiveToken(first.content.trim());
  }

  // Default to object
  return decodeObject(cursor, 0, options);
}