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