Skip to content

Fix ParseFormatControls to handle nested parenthesized groups#4

Merged
philliphoff merged 1 commit into
mainfrom
philliphoff/fix-nested-format-controls
May 19, 2026
Merged

Fix ParseFormatControls to handle nested parenthesized groups#4
philliphoff merged 1 commit into
mainfrom
philliphoff/fix-nested-format-controls

Conversation

@philliphoff
Copy link
Copy Markdown
Owner

Problem

ParseFormatControls in Iso8211DataDescriptiveRecordReader.cs doesn't handle nested parenthesized groups in ISO 8211 format control strings.

A real-world S-101 dataset (Canadian Hydrographic Service) has the C3IL field with format controls (b11,(3b24)). The inner (3b24) is a parenthesized sub-group meaning "3 repetitions of b24". But the parser treats this as a single format part, passes (3b24) to ParseSingleFormat, which sees the leading ( as an unrecognized format character and returns null.

This causes only 1 format entry (b11) to be produced instead of 4 (b11, b24, b24, b24).

Fix

When ParseFormatControls encounters a format part that is itself parenthesized (e.g., (3b24) or 3(b24)), it now:

  1. Parses any leading repeat count before the opening paren
  2. Strips the outer parens
  3. Recursively calls ParseFormatControls on the inner content
  4. Repeats the result for the specified count

This handles all forms of nested groups:

  • (3b24) → 3×b24
  • 3(b24) → 3×b24
  • 2(I(10),b14) → 2×[I(10), b14]

Tests

Added 3 new test cases:

  • (b11,(3b24)) → [b11, b24, b24, b24]
  • (b11,3(b24)) → [b11, b24, b24, b24]
  • (A,2(I(10),b14)) → [A, I(10), b14, I(10), b14]

All 424 existing tests continue to pass.

ParseFormatControls now recursively expands nested parenthesized
sub-groups in ISO 8211 format control strings. For example,
(b11,(3b24)) correctly produces [b11, b24, b24, b24] instead of
only [b11].

When a format part is itself parenthesized (e.g. (3b24) or 3(b24)),
the method strips the outer parens, parses the leading repeat count,
and recursively calls ParseFormatControls on the inner content.

This fixes parsing of S-101 fields like C3IL whose format controls
contain nested groups such as (b11,(3b24)).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@philliphoff philliphoff merged commit db690db into main May 19, 2026
6 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.

1 participant