class CxSmilesParser {

    static String unescape(String str) {
        int dst = 0;
        int src = 0;
        char[] chars = str.toCharArray();
        int len = chars.length;
        while (src < chars.length) {
            // match the pattern &#[0-9][0-9]*;
            if (src + 3 < len && chars[src] == '&' && chars[src+1] == '#' && isDigit(chars[src+2])) {
                int tmp  = src+2;
                int code = 0;
                while (tmp < len && isDigit(chars[tmp])) {
                    code *= 10;
                    code += chars[tmp] - '0';
                    tmp++;
                }
                if (tmp < len && chars[tmp] == ';') {
                    src = tmp+1;
                    chars[dst++] = (char) code;
                    continue;
                }
            }
            chars[dst++] = chars[src++];
        }
        return new String(chars, 0, dst);
    }

    private  CxSmilesParser();

}