Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
// compliance with the InfoGrid license. The InfoGrid license and important

public class Main {
    /**
     * This helper takes a String escaped according to escape and undos the escape.
     * FIXME This is not complete at all.
     *
     * @param enc the escaped String
     * @return the original String
     * @see #escape
     */
    @SuppressWarnings("fallthrough")
    public static final String descape(String enc) {
        StringBuilder ret = new StringBuilder(enc.length()); // same length

        for (int i = 0; i < enc.length(); ++i) {
            char c = enc.charAt(i);
            switch (c) {
            case '&':
                if (enc.charAt(i + 1) == '#') {
                    i += 3; // we simply believe that the next two are going to be #x. FIXME?
                    String s = enc.substring(i);
                    int colonIndex = s.indexOf(';');
                    int v = Integer.parseInt(s.substring(0, colonIndex), 16);

                    ret.append(new Character((char) v));

                    i += colonIndex;
                    break;
                }
                // else run-through

            default:
                ret.append(c);
                break;
            }
        }
        return ret.toString();
    }
}