Class CharPolicy

java.lang.Object
io.github.sergeloie.languagecheck.check.CharPolicy

public final class CharPolicy extends Object
Decides whether a Unicode code point is allowed in a checked file.

Three rule levels, evaluated for every code point:

  1. ASCII (U+0000..U+007F) is always allowed - code, whitespace and punctuation shared by every language.
  2. Formatting code points from the catalog (typography, box drawing, agent emoji, LLM math symbols) are allowed for mapped files whose extension is listed in formattingExtensions, but never for ASCII-only ones.
  3. Any code point inside one of the mapped languages' ranges is allowed.

Instances are immutable and cheap to share across every file that uses the same extension mapping.

  • Method Details

    • asciiOnly

      public static CharPolicy asciiOnly()
      Strict ASCII-only policy: no formatting characters, no language ranges. Used for asciiOnlyExtensions such as .java.
    • forLanguages

      public static CharPolicy forLanguages(List<Language> languages, LanguageCatalog catalog)
      Policy for a set of mapped languages: the union of their character ranges plus the catalog's shared formatting characters.

      An empty language list yields plain "ASCII + formatting" - the natural policy for an English-only mapped document.

    • forLanguages

      public static CharPolicy forLanguages(List<Language> languages, LanguageCatalog catalog, boolean formattingAllowed)
      Policy for a set of mapped languages with explicit control over the global formatting list. When formattingAllowed is false (or the catalog is null), only the languages' alphabets and ASCII pass - no typography, no agent emoji, no LLM math symbols.
    • allows

      public boolean allows(int codePoint)
      True if the code point passes this policy. Ranges are pre-merged and sorted, so lookup is binary-search (O(log n)).