Here you can find the source of charToHTML(char ch, boolean xml)
Parameter | Description |
---|---|
ch | The character to convert. |
xml | Convert the character to XML if set to true. |
public static final String charToHTML(char ch, boolean xml)
//package com.java2s; /*/*from w w w. j av a 2 s. com*/ * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. The ASF licenses this file to You * under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. For additional information regarding * copyright in this work, please see the NOTICE file in the top level * directory of this distribution. */ public class Main { /** * Converts a character to HTML or XML entity. * * @param ch The character to convert. * @param xml Convert the character to XML if set to true. * @author Erik C. Thauvin * * @return The converted string. */ public static final String charToHTML(char ch, boolean xml) { int c; // Convert left bracket if (ch == '<') { return ("<"); } // Convert left bracket else if (ch == '>') { return (">"); } // Convert ampersand else if (ch == '&') { return ("&"); } // Commented out to eliminate redundant numeric character codes (ROL-507) // High-ASCII character //else if (ch >= 128) //{ //c = ch; //return ("&#" + c + ';'); //} // Convert double quote else if (xml && (ch == '"')) { return ("""); } // Convert single quote else if (xml && (ch == '\'')) { return ("'"); } // No conversion else { // Return character as string return (String.valueOf(ch)); } } }