StringNormalizer helps in normalizing strings for the use as payload in QR Invoices.

Simple Use

import ch.codeblock.qrinvoice.model.util.StringNormalizer;

// ...
final StringNormalizer stringNormalizer = StringNormalizer.create()
        .enableAll(); // enables all possible normalizations, does the same as example below

System.out.println(stringNormalizer.normalize(" Instruction\tde\r\n" +
        "«Château-d'Œx» € 100"));
// prints: Instruction de "Château-d'Oex" EUR 100

Fine Grained Use

import ch.codeblock.qrinvoice.model.util.StringNormalizer;

// ...
final StringNormalizer stringNormalizer = StringNormalizer.create()
        .enableTrim() // removes whitespaces the same as String#trim() does
        .enableReplaceLineBreaks() // CRLF, CR and LF gets replaced by single whitespace
        .enableReplaceTabs() // TAB gets replaced by single whitespace
        .enableReplaceCharactersSameLength() // replaces some unsupported characters with supported ones of same length, like different types of dashes with standard dash '-', different quote styles with simple single or double quotes or 'ã' with 'a'
        .enableReplaceCharactersWithMultipleChars() // replaces some unsupported characters with supported ones of different length (usually longer), like 'Œ' with 'Oe' or '€' with 'EUR'
        .enableRemoveUnsupportedCharacters(); // at the end removes all unsupported characters

System.out.println(stringNormalizer.normalize(" Instruction\tde\r\n" +
        "«Château-d'Œx» € 100"));
// prints: Instruction de "Château-d'Oex" EUR 100