001package net.minecraft.util;
002
003import java.io.BufferedReader;
004import java.io.InputStreamReader;
005
006public class ChatAllowedCharacters
007{
008    /**
009     * This String have the characters allowed in any text drawing of minecraft.
010     */
011    public static final String allowedCharacters = getAllowedCharacters();
012
013    /**
014     * Array of the special characters that are allowed in any text drawing of Minecraft.
015     */
016    public static final char[] allowedCharactersArray = new char[] {'/', '\n', '\r', '\t', '\u0000', '\f', '`', '?', '*', '\\', '<', '>', '|', '\"', ':'};
017
018    /**
019     * Load the font.txt resource file, that is on UTF-8 format. This file contains the characters that minecraft can
020     * render Strings on screen.
021     */
022    private static String getAllowedCharacters()
023    {
024        String s = "";
025
026        try
027        {
028            BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(ChatAllowedCharacters.class.getResourceAsStream("/font.txt"), "UTF-8"));
029            String s1 = "";
030
031            while ((s1 = bufferedreader.readLine()) != null)
032            {
033                if (!s1.startsWith("#"))
034                {
035                    s = s + s1;
036                }
037            }
038
039            bufferedreader.close();
040        }
041        catch (Exception exception)
042        {
043            ;
044        }
045
046        return s;
047    }
048
049    public static final boolean isAllowedCharacter(char par0)
050    {
051        return par0 != 167 && (allowedCharacters.indexOf(par0) >= 0 || par0 > 32);
052    }
053
054    /**
055     * Filter string by only keeping those characters for which isAllowedCharacter() returns true.
056     */
057    public static String filerAllowedCharacters(String par0Str)
058    {
059        StringBuilder stringbuilder = new StringBuilder();
060        char[] achar = par0Str.toCharArray();
061        int i = achar.length;
062
063        for (int j = 0; j < i; ++j)
064        {
065            char c0 = achar[j];
066
067            if (isAllowedCharacter(c0))
068            {
069                stringbuilder.append(c0);
070            }
071        }
072
073        return stringbuilder.toString();
074    }
075}