NFKC Folds Fullwidth And Superscript Forms

Fold fullwidth Latin, superscript digits, and ligatures to base letters with NFKC before validating input, so length checks see real characters.

JavaForm Validation

Code

snippet
import java.text.Normalizer;

public class UserInputNormalizer {

    // NFKC folds fullwidth and superscript forms to base letters, 校验前的关键一步
    static String fold(String raw) {
        return Normalizer.normalize(raw, Normalizer.Form.NFKC);
    }

    public static void main(String[] args) {
        String fullwidth = "TOKYO";    // fullwidth Latin
        String superscript = "x² + y³";    // superscript digits
        String ligature = "file";           // fi ligature

        System.out.println(fold(fullwidth));
        System.out.println(fold(superscript));
        System.out.println(fold(ligature));

        // 长度变化:兼容字符折叠后每个字符都还原成基础字母
        System.out.println("file".length() + " -> " + fold("file").length());
    }
}

What the snippet does

The working surface is the class UserInputNormalizer and the functions fold and main — everything else is wiring.

Caveats

  • No outside surface: every behavior is standard library.

Putting it to use

Signature: static String fold(String raw)

Output lines are prefixed (file), so each line of output can be traced back to its step.

main calls 1 helper in sequence: fold.

Core lines

return Normalizer.normalize(raw, Normalizer.Form.NFKC);

Interactive Tools for This Topic

FAQ

What does NFKC Folds Fullwidth And Superscript Forms print when run?
Running the file directly is enough — expect labeled output lines such as `file`.