Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
// modify it under the terms of the GNU General Public License

public class Main {
    public static String escapeAttribute(String value) {
        if (value == null)
            return "";

        StringBuffer result = new StringBuffer(value.length());
        char[] chars = value.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            switch (chars[i]) {
            case '<':
                result.append("&lt;");
                break;
            case '>':
                result.append("&gt;");
                break;
            case '&':
                result.append("&amp;");
                break;
            case '"':
                result.append("&quot;");
                break;
            case '\'':
                result.append("&apos;");
                break;
            default:
                if (chars[i] < 32)
                    result.append("&#").append((int) chars[i]).append(";");
                else
                    result.append(chars[i]);
            }
        }
        return result.toString();
    }
}