Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
// Use and redistribution of this file is governed by the license terms in

public class Main {
    public static String escapeXML(final String text) {
        final StringBuilder sb = new StringBuilder();
        final int len = text.length();
        for (int i = 0; i < len; i++) {
            final char c = text.charAt(i);
            switch (c) {
            case 34:
                sb.append("&quot;");
                break;
            case 38:
                sb.append("&amp;");
                break;
            case 39:
                sb.append("&apos;");
                break;
            case 60:
                sb.append("&lt;");
                break;
            case 62:
                sb.append("&gt;");
                break;
            default:
                if (c > 0x7F) {
                    sb.append("&#");
                    sb.append(Integer.toString(c, 10));
                    sb.append(';');
                } else {
                    sb.append(c);
                }
            }
        }
        return sb.toString();
    }
}