OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Blame | Last modification | View Log | RSS feed

package org.openconcerto.modules.label;

public class ISO646 {
    public static final String ALLOWED_CHARS = "!\"%&'()*+,-./01234567989:;<=>?ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz";

    public static boolean isValid(char c) {
        final int length = ALLOWED_CHARS.length();
        for (int i = 0; i < length; i++) {
            if (c == ALLOWED_CHARS.charAt(i)) {
                return true;
            }
        }
        return false;
    }

    public static String clean(String s) {
        final int length = s.length();
        final StringBuilder b = new StringBuilder(length);
        for (int i = 0; i < length; i++) {
            final char charAt = s.charAt(i);
            if (isValid(charAt)) {
                b.append(s.charAt(i));
            } else {
                b.append('_');
            }
        }
        return b.toString();
    }

}