Pattern Tool Updated (C++)

Full explanation of the updated LostSideDead-style overlapping-letter chain and group logic, plus the working C++ source. Copy or download the source with includes intact.

1. High-level Pattern

This tool detects identifiers like LostSideDead by decomposing, extracting two-letter pairs, chaining overlapping letters, and enforcing a structured non-decreasing group sequence. The output highlights:

  • Words split from a CamelCase token.
  • Pairs per word using the updated toggle-aware rule.
  • Acronym built from leading letters.
  • Chain links showing overlaps and case toggles.
  • Group sequence over flattened letters (e.g., L s S d D d) that must be non-decreasing unless disabled.

2. Detailed Logic

Step-by-step:

  1. CamelCase splitting: A token like LostSideDead is split into words at uppercase boundaries, preserving consecutive uppercase runs (e.g., JSONDataJSON, Data).
  2. Pair extraction: For each word:
    • If the first and last characters match ignoring case (e.g., Dead, Level), produce Upper(first)+lower(first) to surface a case-toggle, e.g., DeadDd, LevelLl.
    • Else if length ≥3, take first+third (e.g., LostLs, SideSd).
    • Fallbacks: length 2 → first+second; length 1 → duplicated letter.
  3. Acronym: Concatenate the first letters of each word, uppercased (e.g., LSD).
  4. Overlap chain detection: Adjacent pairs are linked if the second character of one equals the first of the next (case-insensitive). Differences in case are noted as toggles.
  5. Group numbering: Flatten the letters of the pairs into a sequence (e.g., Ls Sd DdL s S d D d) and assign group numbers:
    • Start with group 1 on the first letter.
    • The second letter of a pair increments if it differs (case-insensitive) from the first, otherwise stays.
    • The first letter of a subsequent pair reuses the previous group if it overlaps; otherwise it increments.
    • The second letter of that pair similarly increments only if different from its own first letter.
    The resulting group sequence must be non-decreasing (e.g., 1 2 2 3 3 3 for LostSideDead) unless the group check is turned off.

3. Example: LostSideDead

Pattern found: LostSideDead Words: Lost, Side, Dead Pairs: Ls, Sd, Dd Acronym: LSD Groups: 1 2 2 3 3 3 Chain links: Ls -> Sd : overlap='yes' (case toggle on 's') Sd -> Dd : overlap='yes' (case toggle on 'd') Score: 2 / 2 overlapping link(s)

This shows the full breakdown: the pair from “Dead” is Dd because first and last letter match ignoring case; the flattened letters produce a non-decreasing group sequence 1 2 2 3 3 3, and both overlaps exist with case toggles flagged.

4. Usage

Compile:

g++ -std=c++17 -O2 -o pattern_tool_updated pattern_tool_updated.cpp

Run: Supply input via pipe or files:

echo "LostSideDead ExampleToken" | ./pattern_tool_updated

Flags:

  • --no-group-check — do not require the flattened group sequence to be non-decreasing; still requires at least one overlap.
  • -h / --help — show usage.

C++ Source: pattern_tool_updated.cpp

Implements all of the above: splitting, toggle-aware pair extraction, overlap detection, group sequencing, and optional enforcement.