INNER CODE UNIT · TypeScript

COMPOUND_WORD_PATTERN

vinta/pangu.js · src/shared/index.ts:398

    const COMPOUND_WORD_PATTERN = /\b(?:[A-Za-z0-9]*[a-z][A-Za-z0-9]*-[A-Za-z0-9]+|[A-Za-z0-9]+-[A-Za-z0-9]*[a-z][A-Za-z0-9]*|[A-Za-z]+-[0-9]+|[A-Za-z]+[0-9]+-[A-Za-z0-9]+)(?:-[A-Za-z0-9]+)*\b/g;

    newText = newText.replace(COMPOUND_WORD_PATTERN, (match) => {
      return compoundWordManager.store(match);
    });

    // Single-letter grades run before the general operator rules so A+CJK becomes A+ CJK, not A + CJK
    newText = newText.replace(SINGLE_LETTER_GRADE_CJK, '$1$2 $3');

    // Affix readings run before the operator rules so the symbol stays attached to its half-width side
    newText = newText.replace(CJK_SIGN_DIGIT, '$1 $2$3');
    newText = newText.replace(CJK_HYPHEN_FLAG, '$1 $2$3');
    newText = newText.replace(DIGIT_PLUS_CJK, '$1$2 $3');

    // Plus reading is per line: a plus in direct contact with CJK makes every undecided plus on the line a separator with spaces on both sides, as in telecom bundle plans that chain products with +
    // A decided plus keeps its reading: space-adjacent, affix-attached (100+, +886), or in a ++ run (C++). A line with no CJK contact keeps its joiner tokens tight (A+B, 5+5)
    // It runs right after the affixes and before the operator rules, so a CJK+A contact flips the line's joiners like a CJK+CJK contact does (CJK+A+A reads CJK + A + A)
    // Name suffixes are recognized here so their CJK contact still decides the line's other pluses (Disney+CJK A+B)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…