    001/*
    002 * Licensed to the Apache Software Foundation (ASF) under one or more
    003 * contributor license agreements.  See the NOTICE file distributed with
    004 * this work for additional information regarding copyright ownership.
    005 * The ASF licenses this file to You under the Apache License, Version 2.0
    006 * (the "License"); you may not use this file except in compliance with
    007 * the License.  You may obtain a copy of the License at
    008 *
    009 *      http://www.apache.org/licenses/LICENSE-2.0
    010 *
    011 * Unless required by applicable law or agreed to in writing, software
    012 * distributed under the License is distributed on an "AS IS" BASIS,
    013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014 * See the License for the specific language governing permissions and
    015 * limitations under the License.
    016 */
    017package org.apache.commons.text.translate;
    018
    019import java.util.Collections;
    020import java.util.HashMap;
    021import java.util.Map;
    022
    023/**
    024 * Class holding various entity data for HTML and XML - generally for use with
    025 * the LookupTranslator.
    026 * All Maps are generated using {@code java.util.Collections.unmodifiableMap()}.
    027 *
    028 * @since 1.0
    029 */
    030public class EntityArrays {
    031
    032   /**
    033     * A Map&lt;CharSequence, CharSequence&gt; to to escape
    034     * <a href="https://secure.wikimedia.org/wikipedia/en/wiki/ISO/IEC_8859-1">ISO-8859-1</a>
    035     * characters to their named HTML 3.x equivalents.
    036     */
    037    public static final Map<CharSequence, CharSequence> ISO8859_1_ESCAPE;
    038    static {
    039        final Map<CharSequence, CharSequence> initialMap = new HashMap<>();
    040        initialMap.put("\u00A0", "&nbsp;"); // non-breaking space
    041        initialMap.put("\u00A1", "&iexcl;"); // inverted exclamation mark
    042        initialMap.put("\u00A2", "&cent;"); // cent sign
    043        initialMap.put("\u00A3", "&pound;"); // pound sign
    044        initialMap.put("\u00A4", "&curren;"); // currency sign
    045        initialMap.put("\u00A5", "&yen;"); // yen sign = yuan sign
    046        initialMap.put("\u00A6", "&brvbar;"); // broken bar = broken vertical bar
    047        initialMap.put("\u00A7", "&sect;"); // section sign
    048        initialMap.put("\u00A8", "&uml;"); // diaeresis = spacing diaeresis
    049        initialMap.put("\u00A9", "&copy;"); // © - copyright sign
    050        initialMap.put("\u00AA", "&ordf;"); // feminine ordinal indicator
    051        initialMap.put("\u00AB", "&laquo;"); // left-pointing double angle quotation mark = left pointing guillemet
    052        initialMap.put("\u00AC", "&not;"); // not sign
    053        initialMap.put("\u00AD", "&shy;"); // soft hyphen = discretionary hyphen
    054        initialMap.put("\u00AE", "&reg;"); // ® - registered trademark sign
    055        initialMap.put("\u00AF", "&macr;"); // macron = spacing macron = overline = APL overbar
    056        initialMap.put("\u00B0", "&deg;"); // degree sign
    057        initialMap.put("\u00B1", "&plusmn;"); // plus-minus sign = plus-or-minus sign
    058        initialMap.put("\u00B2", "&sup2;"); // superscript two = superscript digit two = squared
    059        initialMap.put("\u00B3", "&sup3;"); // superscript three = superscript digit three = cubed
    060        initialMap.put("\u00B4", "&acute;"); // acute accent = spacing acute
    061        initialMap.put("\u00B5", "&micro;"); // micro sign
    062        initialMap.put("\u00B6", "&para;"); // pilcrow sign = paragraph sign
    063        initialMap.put("\u00B7", "&middot;"); // middle dot = Georgian comma = Greek middle dot
    064        initialMap.put("\u00B8", "&cedil;"); // cedilla = spacing cedilla
    065        initialMap.put("\u00B9", "&sup1;"); // superscript one = superscript digit one
    066        initialMap.put("\u00BA", "&ordm;"); // masculine ordinal indicator
    067        initialMap.put("\u00BB", "&raquo;"); // right-pointing double angle quotation mark = right pointing guillemet
    068        initialMap.put("\u00BC", "&frac14;"); // vulgar fraction one quarter = fraction one quarter
    069        initialMap.put("\u00BD", "&frac12;"); // vulgar fraction one half = fraction one half
    070        initialMap.put("\u00BE", "&frac34;"); // vulgar fraction three quarters = fraction three quarters
    071        initialMap.put("\u00BF", "&iquest;"); // inverted question mark = turned question mark
    072        initialMap.put("\u00C0", "&Agrave;"); // À - uppercase A, grave accent
    073        initialMap.put("\u00C1", "&Aacute;"); // Á - uppercase A, acute accent
    074        initialMap.put("\u00C2", "&Acirc;"); // Â - uppercase A, circumflex accent
    075        initialMap.put("\u00C3", "&Atilde;"); // Ã - uppercase A, tilde
    076        initialMap.put("\u00C4", "&Auml;"); // Ä - uppercase A, umlaut
    077        initialMap.put("\u00C5", "&Aring;"); // Å - uppercase A, ring
    078        initialMap.put("\u00C6", "&AElig;"); // Æ - uppercase AE
    079        initialMap.put("\u00C7", "&Ccedil;"); // Ç - uppercase C, cedilla
    080        initialMap.put("\u00C8", "&Egrave;"); // È - uppercase E, grave accent
    081        initialMap.put("\u00C9", "&Eacute;"); // É - uppercase E, acute accent
    082        initialMap.put("\u00CA", "&Ecirc;"); // Ê - uppercase E, circumflex accent
    083        initialMap.put("\u00CB", "&Euml;"); // Ë - uppercase E, umlaut
    084        initialMap.put("\u00CC", "&Igrave;"); // Ì - uppercase I, grave accent
    085        initialMap.put("\u00CD", "&Iacute;"); // Í - uppercase I, acute accent
    086        initialMap.put("\u00CE", "&Icirc;"); // Î - uppercase I, circumflex accent
    087        initialMap.put("\u00CF", "&Iuml;"); // Ï - uppercase I, umlaut
    088        initialMap.put("\u00D0", "&ETH;"); // Ð - uppercase Eth, Icelandic
    089        initialMap.put("\u00D1", "&Ntilde;"); // Ñ - uppercase N, tilde
    090        initialMap.put("\u00D2", "&Ograve;"); // Ò - uppercase O, grave accent
    091        initialMap.put("\u00D3", "&Oacute;"); // Ó - uppercase O, acute accent
    092        initialMap.put("\u00D4", "&Ocirc;"); // Ô - uppercase O, circumflex accent
    093        initialMap.put("\u00D5", "&Otilde;"); // Õ - uppercase O, tilde
    094        initialMap.put("\u00D6", "&Ouml;"); // Ö - uppercase O, umlaut
    095        initialMap.put("\u00D7", "&times;"); // multiplication sign
    096        initialMap.put("\u00D8", "&Oslash;"); // Ø - uppercase O, slash
    097        initialMap.put("\u00D9", "&Ugrave;"); // Ù - uppercase U, grave accent
    098        initialMap.put("\u00DA", "&Uacute;"); // Ú - uppercase U, acute accent
    099        initialMap.put("\u00DB", "&Ucirc;"); // Û - uppercase U, circumflex accent
    100        initialMap.put("\u00DC", "&Uuml;"); // Ü - uppercase U, umlaut
    101        initialMap.put("\u00DD", "&Yacute;"); // Ý - uppercase Y, acute accent
    102        initialMap.put("\u00DE", "&THORN;"); // Þ - uppercase THORN, Icelandic
    103        initialMap.put("\u00DF", "&szlig;"); // ß - lowercase sharps, German
    104        initialMap.put("\u00E0", "&agrave;"); // à - lowercase a, grave accent
    105        initialMap.put("\u00E1", "&aacute;"); // á - lowercase a, acute accent
    106        initialMap.put("\u00E2", "&acirc;"); // â - lowercase a, circumflex accent
    107        initialMap.put("\u00E3", "&atilde;"); // ã - lowercase a, tilde
    108        initialMap.put("\u00E4", "&auml;"); // ä - lowercase a, umlaut
    109        initialMap.put("\u00E5", "&aring;"); // å - lowercase a, ring
    110        initialMap.put("\u00E6", "&aelig;"); // æ - lowercase ae
    111        initialMap.put("\u00E7", "&ccedil;"); // ç - lowercase c, cedilla
    112        initialMap.put("\u00E8", "&egrave;"); // è - lowercase e, grave accent
    113        initialMap.put("\u00E9", "&eacute;"); // é - lowercase e, acute accent
    114        initialMap.put("\u00EA", "&ecirc;"); // ê - lowercase e, circumflex accent
    115        initialMap.put("\u00EB", "&euml;"); // ë - lowercase e, umlaut
    116        initialMap.put("\u00EC", "&igrave;"); // ì - lowercase i, grave accent
    117        initialMap.put("\u00ED", "&iacute;"); // í - lowercase i, acute accent
    118        initialMap.put("\u00EE", "&icirc;"); // î - lowercase i, circumflex accent
    119        initialMap.put("\u00EF", "&iuml;"); // ï - lowercase i, umlaut
    120        initialMap.put("\u00F0", "&eth;"); // ð - lowercase eth, Icelandic
    121        initialMap.put("\u00F1", "&ntilde;"); // ñ - lowercase n, tilde
    122        initialMap.put("\u00F2", "&ograve;"); // ò - lowercase o, grave accent
    123        initialMap.put("\u00F3", "&oacute;"); // ó - lowercase o, acute accent
    124        initialMap.put("\u00F4", "&ocirc;"); // ô - lowercase o, circumflex accent
    125        initialMap.put("\u00F5", "&otilde;"); // õ - lowercase o, tilde
    126        initialMap.put("\u00F6", "&ouml;"); // ö - lowercase o, umlaut
    127        initialMap.put("\u00F7", "&divide;"); // division sign
    128        initialMap.put("\u00F8", "&oslash;"); // ø - lowercase o, slash
    129        initialMap.put("\u00F9", "&ugrave;"); // ù - lowercase u, grave accent
    130        initialMap.put("\u00FA", "&uacute;"); // ú - lowercase u, acute accent
    131        initialMap.put("\u00FB", "&ucirc;"); // û - lowercase u, circumflex accent
    132        initialMap.put("\u00FC", "&uuml;"); // ü - lowercase u, umlaut
    133        initialMap.put("\u00FD", "&yacute;"); // ý - lowercase y, acute accent
    134        initialMap.put("\u00FE", "&thorn;"); // þ - lowercase thorn, Icelandic
    135        initialMap.put("\u00FF", "&yuml;"); // ÿ - lowercase y, umlaut
    136        ISO8859_1_ESCAPE = Collections.unmodifiableMap(initialMap);
    137    }
    138
    139    /**
    140     * Reverse of {@link #ISO8859_1_ESCAPE} for unescaping purposes.
    141     */
    142    public static final Map<CharSequence, CharSequence> ISO8859_1_UNESCAPE;
    143    static {
    144        ISO8859_1_UNESCAPE = Collections.unmodifiableMap(invert(ISO8859_1_ESCAPE));
    145    }
    146
    147    /**
    148     * A Map&lt;CharSequence, CharSequence&gt; to escape additional
    149     * <a href="http://www.w3.org/TR/REC-html40/sgml/entities.html">character entity
    150     * references</a>. Note that this must be used with {@link #ISO8859_1_ESCAPE} to get the full list of
    151     * HTML 4.0 character entities.
    152     */
    153    public static final Map<CharSequence, CharSequence> HTML40_EXTENDED_ESCAPE;
    154    static {
    155        final Map<CharSequence, CharSequence> initialMap = new HashMap<>();
    156        // <!-- Latin Extended-B -->
    157        initialMap.put("\u0192", "&fnof;"); // latin small f with hook = function= florin, U+0192 ISOtech -->
    158        // <!-- Greek -->
    159        initialMap.put("\u0391", "&Alpha;"); // greek capital letter alpha, U+0391 -->
    160        initialMap.put("\u0392", "&Beta;"); // greek capital letter beta, U+0392 -->
    161        initialMap.put("\u0393", "&Gamma;"); // greek capital letter gamma,U+0393 ISOgrk3 -->
    162        initialMap.put("\u0394", "&Delta;"); // greek capital letter delta,U+0394 ISOgrk3 -->
    163        initialMap.put("\u0395", "&Epsilon;"); // greek capital letter epsilon, U+0395 -->
    164        initialMap.put("\u0396", "&Zeta;"); // greek capital letter zeta, U+0396 -->
    165        initialMap.put("\u0397", "&Eta;"); // greek capital letter eta, U+0397 -->
    166        initialMap.put("\u0398", "&Theta;"); // greek capital letter theta,U+0398 ISOgrk3 -->
    167        initialMap.put("\u0399", "&Iota;"); // greek capital letter iota, U+0399 -->
    168        initialMap.put("\u039A", "&Kappa;"); // greek capital letter kappa, U+039A -->
    169        initialMap.put("\u039B", "&Lambda;"); // greek capital letter lambda,U+039B ISOgrk3 -->
    170        initialMap.put("\u039C", "&Mu;"); // greek capital letter mu, U+039C -->
    171        initialMap.put("\u039D", "&Nu;"); // greek capital letter nu, U+039D -->
    172        initialMap.put("\u039E", "&Xi;"); // greek capital letter xi, U+039E ISOgrk3 -->
    173        initialMap.put("\u039F", "&Omicron;"); // greek capital letter omicron, U+039F -->
    174        initialMap.put("\u03A0", "&Pi;"); // greek capital letter pi, U+03A0 ISOgrk3 -->
    175        initialMap.put("\u03A1", "&Rho;"); // greek capital letter rho, U+03A1 -->
    176        // <!-- there is no Sigmaf, and no U+03A2 character either -->
    177        initialMap.put("\u03A3", "&Sigma;"); // greek capital letter sigma,U+03A3 ISOgrk3 -->
    178        initialMap.put("\u03A4", "&Tau;"); // greek capital letter tau, U+03A4 -->
    179        initialMap.put("\u03A5", "&Upsilon;"); // greek capital letter upsilon,U+03A5 ISOgrk3 -->
    180        initialMap.put("\u03A6", "&Phi;"); // greek capital letter phi,U+03A6 ISOgrk3 -->
    181        initialMap.put("\u03A7", "&Chi;"); // greek capital letter chi, U+03A7 -->
    182        initialMap.put("\u03A8", "&Psi;"); // greek capital letter psi,U+03A8 ISOgrk3 -->
    183        initialMap.put("\u03A9", "&Omega;"); // greek capital letter omega,U+03A9 ISOgrk3 -->
    184        initialMap.put("\u03B1", "&alpha;"); // greek small letter alpha,U+03B1 ISOgrk3 -->
    185        initialMap.put("\u03B2", "&beta;"); // greek small letter beta, U+03B2 ISOgrk3 -->
    186        initialMap.put("\u03B3", "&gamma;"); // greek small letter gamma,U+03B3 ISOgrk3 -->
    187        initialMap.put("\u03B4", "&delta;"); // greek small letter delta,U+03B4 ISOgrk3 -->
    188        initialMap.put("\u03B5", "&epsilon;"); // greek small letter epsilon,U+03B5 ISOgrk3 -->
    189        initialMap.put("\u03B6", "&zeta;"); // greek small letter zeta, U+03B6 ISOgrk3 -->
    190        initialMap.put("\u03B7", "&eta;"); // greek small letter eta, U+03B7 ISOgrk3 -->
    191        initialMap.put("\u03B8", "&theta;"); // greek small letter theta,U+03B8 ISOgrk3 -->
    192        initialMap.put("\u03B9", "&iota;"); // greek small letter iota, U+03B9 ISOgrk3 -->
    193        initialMap.put("\u03BA", "&kappa;"); // greek small letter kappa,U+03BA ISOgrk3 -->
    194        initialMap.put("\u03BB", "&lambda;"); // greek small letter lambda,U+03BB ISOgrk3 -->
    195        initialMap.put("\u03BC", "&mu;"); // greek small letter mu, U+03BC ISOgrk3 -->
    196        initialMap.put("\u03BD", "&nu;"); // greek small letter nu, U+03BD ISOgrk3 -->
    197        initialMap.put("\u03BE", "&xi;"); // greek small letter xi, U+03BE ISOgrk3 -->
    198        initialMap.put("\u03BF", "&omicron;"); // greek small letter omicron, U+03BF NEW -->
    199        initialMap.put("\u03C0", "&pi;"); // greek small letter pi, U+03C0 ISOgrk3 -->
    200        initialMap.put("\u03C1", "&rho;"); // greek small letter rho, U+03C1 ISOgrk3 -->
    201        initialMap.put("\u03C2", "&sigmaf;"); // greek small letter final sigma,U+03C2 ISOgrk3 -->
    202        initialMap.put("\u03C3", "&sigma;"); // greek small letter sigma,U+03C3 ISOgrk3 -->
    203        initialMap.put("\u03C4", "&tau;"); // greek small letter tau, U+03C4 ISOgrk3 -->
    204        initialMap.put("\u03C5", "&upsilon;"); // greek small letter upsilon,U+03C5 ISOgrk3 -->
    205        initialMap.put("\u03C6", "&phi;"); // greek small letter phi, U+03C6 ISOgrk3 -->
    206        initialMap.put("\u03C7", "&chi;"); // greek small letter chi, U+03C7 ISOgrk3 -->
    207        initialMap.put("\u03C8", "&psi;"); // greek small letter psi, U+03C8 ISOgrk3 -->
    208        initialMap.put("\u03C9", "&omega;"); // greek small letter omega,U+03C9 ISOgrk3 -->
    209        initialMap.put("\u03D1", "&thetasym;"); // greek small letter theta symbol,U+03D1 NEW -->
    210        initialMap.put("\u03D2", "&upsih;"); // greek upsilon with hook symbol,U+03D2 NEW -->
    211        initialMap.put("\u03D6", "&piv;"); // greek pi symbol, U+03D6 ISOgrk3 -->
    212        // <!-- General Punctuation -->
    213        initialMap.put("\u2022", "&bull;"); // bullet = black small circle,U+2022 ISOpub -->
    214        // <!-- bullet is NOT the same as bullet operator, U+2219 -->
    215        initialMap.put("\u2026", "&hellip;"); // horizontal ellipsis = three dot leader,U+2026 ISOpub -->
    216        initialMap.put("\u2032", "&prime;"); // prime = minutes = feet, U+2032 ISOtech -->
    217        initialMap.put("\u2033", "&Prime;"); // double prime = seconds = inches,U+2033 ISOtech -->
    218        initialMap.put("\u203E", "&oline;"); // overline = spacing overscore,U+203E NEW -->
    219        initialMap.put("\u2044", "&frasl;"); // fraction slash, U+2044 NEW -->
    220        // <!-- Letterlike Symbols -->
    221        initialMap.put("\u2118", "&weierp;"); // script capital P = power set= Weierstrass p, U+2118 ISOamso -->
    222        initialMap.put("\u2111", "&image;"); // blackletter capital I = imaginary part,U+2111 ISOamso -->
    223        initialMap.put("\u211C", "&real;"); // blackletter capital R = real part symbol,U+211C ISOamso -->
    224        initialMap.put("\u2122", "&trade;"); // trade mark sign, U+2122 ISOnum -->
    225        initialMap.put("\u2135", "&alefsym;"); // alef symbol = first transfinite cardinal,U+2135 NEW -->
    226        // <!-- alef symbol is NOT the same as hebrew letter alef,U+05D0 although the
    227        // same glyph could be used to depict both characters -->
    228        // <!-- Arrows -->
    229        initialMap.put("\u2190", "&larr;"); // leftwards arrow, U+2190 ISOnum -->
    230        initialMap.put("\u2191", "&uarr;"); // upwards arrow, U+2191 ISOnum-->
    231        initialMap.put("\u2192", "&rarr;"); // rightwards arrow, U+2192 ISOnum -->
    232        initialMap.put("\u2193", "&darr;"); // downwards arrow, U+2193 ISOnum -->
    233        initialMap.put("\u2194", "&harr;"); // left right arrow, U+2194 ISOamsa -->
    234        initialMap.put("\u21B5", "&crarr;"); // downwards arrow with corner leftwards= carriage return, U+21B5 NEW -->
    235        initialMap.put("\u21D0", "&lArr;"); // leftwards double arrow, U+21D0 ISOtech -->
    236        // <!-- ISO 10646 does not say that lArr is the same as the 'is implied by'
    237        // arrow but also does not have any other character for that function.
    238        // So ? lArr canbe used for 'is implied by' as ISOtech suggests -->
    239        initialMap.put("\u21D1", "&uArr;"); // upwards double arrow, U+21D1 ISOamsa -->
    240        initialMap.put("\u21D2", "&rArr;"); // rightwards double arrow,U+21D2 ISOtech -->
    241        // <!-- ISO 10646 does not say this is the 'implies' character but does not
    242        // have another character with this function so ?rArr can be used for
    243        // 'implies' as ISOtech suggests -->
    244        initialMap.put("\u21D3", "&dArr;"); // downwards double arrow, U+21D3 ISOamsa -->
    245        initialMap.put("\u21D4", "&hArr;"); // left right double arrow,U+21D4 ISOamsa -->
    246        // <!-- Mathematical Operators -->
    247        initialMap.put("\u2200", "&forall;"); // for all, U+2200 ISOtech -->
    248        initialMap.put("\u2202", "&part;"); // partial differential, U+2202 ISOtech -->
    249        initialMap.put("\u2203", "&exist;"); // there exists, U+2203 ISOtech -->
    250        initialMap.put("\u2205", "&empty;"); // empty set = null set = diameter,U+2205 ISOamso -->
    251        initialMap.put("\u2207", "&nabla;"); // nabla = backward difference,U+2207 ISOtech -->
    252        initialMap.put("\u2208", "&isin;"); // element of, U+2208 ISOtech -->
    253        initialMap.put("\u2209", "&notin;"); // not an element of, U+2209 ISOtech -->
    254        initialMap.put("\u220B", "&ni;"); // contains as member, U+220B ISOtech -->
    255        // <!-- should there be a more memorable name than 'ni'? -->
    256        initialMap.put("\u220F", "&prod;"); // n-ary product = product sign,U+220F ISOamsb -->
    257        // <!-- prod is NOT the same character as U+03A0 'greek capital letter pi'
    258        // though the same glyph might be used for both -->
    259        initialMap.put("\u2211", "&sum;"); // n-ary summation, U+2211 ISOamsb -->
    260        // <!-- sum is NOT the same character as U+03A3 'greek capital letter sigma'
    261        // though the same glyph might be used for both -->
    262        initialMap.put("\u2212", "&minus;"); // minus sign, U+2212 ISOtech -->
    263        initialMap.put("\u2217", "&lowast;"); // asterisk operator, U+2217 ISOtech -->
    264        initialMap.put("\u221A", "&radic;"); // square root = radical sign,U+221A ISOtech -->
    265        initialMap.put("\u221D", "&prop;"); // proportional to, U+221D ISOtech -->
    266        initialMap.put("\u221E", "&infin;"); // infinity, U+221E ISOtech -->
    267        initialMap.put("\u2220", "&ang;"); // angle, U+2220 ISOamso -->
    268        initialMap.put("\u2227", "&and;"); // logical and = wedge, U+2227 ISOtech -->
    269        initialMap.put("\u2228", "&or;"); // logical or = vee, U+2228 ISOtech -->
    270        initialMap.put("\u2229", "&cap;"); // intersection = cap, U+2229 ISOtech -->
    271        initialMap.put("\u222A", "&cup;"); // union = cup, U+222A ISOtech -->
    272        initialMap.put("\u222B", "&int;"); // integral, U+222B ISOtech -->
    273        initialMap.put("\u2234", "&there4;"); // therefore, U+2234 ISOtech -->
    274        initialMap.put("\u223C", "&sim;"); // tilde operator = varies with = similar to,U+223C ISOtech -->
    275        // <!-- tilde operator is NOT the same character as the tilde, U+007E,although
    276        // the same glyph might be used to represent both -->
    277        initialMap.put("\u2245", "&cong;"); // approximately equal to, U+2245 ISOtech -->
    278        initialMap.put("\u2248", "&asymp;"); // almost equal to = asymptotic to,U+2248 ISOamsr -->
    279        initialMap.put("\u2260", "&ne;"); // not equal to, U+2260 ISOtech -->
    280        initialMap.put("\u2261", "&equiv;"); // identical to, U+2261 ISOtech -->
    281        initialMap.put("\u2264", "&le;"); // less-than or equal to, U+2264 ISOtech -->
    282        initialMap.put("\u2265", "&ge;"); // greater-than or equal to,U+2265 ISOtech -->
    283        initialMap.put("\u2282", "&sub;"); // subset of, U+2282 ISOtech -->
    284        initialMap.put("\u2283", "&sup;"); // superset of, U+2283 ISOtech -->
    285        // <!-- note that nsup, 'not a superset of, U+2283' is not covered by the
    286        // Symbol font encoding and is not included. Should it be, for symmetry?
    287        // It is in ISOamsn -->,
    288        initialMap.put("\u2284", "&nsub;"); // not a subset of, U+2284 ISOamsn -->
    289        initialMap.put("\u2286", "&sube;"); // subset of or equal to, U+2286 ISOtech -->
    290        initialMap.put("\u2287", "&supe;"); // superset of or equal to,U+2287 ISOtech -->
    291        initialMap.put("\u2295", "&oplus;"); // circled plus = direct sum,U+2295 ISOamsb -->
    292        initialMap.put("\u2297", "&otimes;"); // circled times = vector product,U+2297 ISOamsb -->
    293        initialMap.put("\u22A5", "&perp;"); // up tack = orthogonal to = perpendicular,U+22A5 ISOtech -->
    294        initialMap.put("\u22C5", "&sdot;"); // dot operator, U+22C5 ISOamsb -->
    295        // <!-- dot operator is NOT the same character as U+00B7 middle dot -->
    296        // <!-- Miscellaneous Technical -->
    297        initialMap.put("\u2308", "&lceil;"); // left ceiling = apl upstile,U+2308 ISOamsc -->
    298        initialMap.put("\u2309", "&rceil;"); // right ceiling, U+2309 ISOamsc -->
    299        initialMap.put("\u230A", "&lfloor;"); // left floor = apl downstile,U+230A ISOamsc -->
    300        initialMap.put("\u230B", "&rfloor;"); // right floor, U+230B ISOamsc -->
    301        initialMap.put("\u2329", "&lang;"); // left-pointing angle bracket = bra,U+2329 ISOtech -->
    302        // <!-- lang is NOT the same character as U+003C 'less than' or U+2039 'single left-pointing angle quotation
    303        // mark' -->
    304        initialMap.put("\u232A", "&rang;"); // right-pointing angle bracket = ket,U+232A ISOtech -->
    305        // <!-- rang is NOT the same character as U+003E 'greater than' or U+203A
    306        // 'single right-pointing angle quotation mark' -->
    307        // <!-- Geometric Shapes -->
    308        initialMap.put("\u25CA", "&loz;"); // lozenge, U+25CA ISOpub -->
    309        // <!-- Miscellaneous Symbols -->
    310        initialMap.put("\u2660", "&spades;"); // black spade suit, U+2660 ISOpub -->
    311        // <!-- black here seems to mean filled as opposed to hollow -->
    312        initialMap.put("\u2663", "&clubs;"); // black club suit = shamrock,U+2663 ISOpub -->
    313        initialMap.put("\u2665", "&hearts;"); // black heart suit = valentine,U+2665 ISOpub -->
    314        initialMap.put("\u2666", "&diams;"); // black diamond suit, U+2666 ISOpub -->
    315
    316        // <!-- Latin Extended-A -->
    317        initialMap.put("\u0152", "&OElig;"); // -- latin capital ligature OE,U+0152 ISOlat2 -->
    318        initialMap.put("\u0153", "&oelig;"); // -- latin small ligature oe, U+0153 ISOlat2 -->
    319        // <!-- ligature is a misnomer, this is a separate character in some languages -->
    320        initialMap.put("\u0160", "&Scaron;"); // -- latin capital letter S with caron,U+0160 ISOlat2 -->
    321        initialMap.put("\u0161", "&scaron;"); // -- latin small letter s with caron,U+0161 ISOlat2 -->
    322        initialMap.put("\u0178", "&Yuml;"); // -- latin capital letter Y with diaeresis,U+0178 ISOlat2 -->
    323        // <!-- Spacing Modifier Letters -->
    324        initialMap.put("\u02C6", "&circ;"); // -- modifier letter circumflex accent,U+02C6 ISOpub -->
    325        initialMap.put("\u02DC", "&tilde;"); // small tilde, U+02DC ISOdia -->
    326        // <!-- General Punctuation -->
    327        initialMap.put("\u2002", "&ensp;"); // en space, U+2002 ISOpub -->
    328        initialMap.put("\u2003", "&emsp;"); // em space, U+2003 ISOpub -->
    329        initialMap.put("\u2009", "&thinsp;"); // thin space, U+2009 ISOpub -->
    330        initialMap.put("\u200C", "&zwnj;"); // zero width non-joiner,U+200C NEW RFC 2070 -->
    331        initialMap.put("\u200D", "&zwj;"); // zero width joiner, U+200D NEW RFC 2070 -->
    332        initialMap.put("\u200E", "&lrm;"); // left-to-right mark, U+200E NEW RFC 2070 -->
    333        initialMap.put("\u200F", "&rlm;"); // right-to-left mark, U+200F NEW RFC 2070 -->
    334        initialMap.put("\u2013", "&ndash;"); // en dash, U+2013 ISOpub -->
    335        initialMap.put("\u2014", "&mdash;"); // em dash, U+2014 ISOpub -->
    336        initialMap.put("\u2018", "&lsquo;"); // left single quotation mark,U+2018 ISOnum -->
    337        initialMap.put("\u2019", "&rsquo;"); // right single quotation mark,U+2019 ISOnum -->
    338        initialMap.put("\u201A", "&sbquo;"); // single low-9 quotation mark, U+201A NEW -->
    339        initialMap.put("\u201C", "&ldquo;"); // left double quotation mark,U+201C ISOnum -->
    340        initialMap.put("\u201D", "&rdquo;"); // right double quotation mark,U+201D ISOnum -->
    341        initialMap.put("\u201E", "&bdquo;"); // double low-9 quotation mark, U+201E NEW -->
    342        initialMap.put("\u2020", "&dagger;"); // dagger, U+2020 ISOpub -->
    343        initialMap.put("\u2021", "&Dagger;"); // double dagger, U+2021 ISOpub -->
    344        initialMap.put("\u2030", "&permil;"); // per mille sign, U+2030 ISOtech -->
    345        initialMap.put("\u2039", "&lsaquo;"); // single left-pointing angle quotation mark,U+2039 ISO proposed -->
    346        // <!-- lsaquo is proposed but not yet ISO standardized -->
    347        initialMap.put("\u203A", "&rsaquo;"); // single right-pointing angle quotation mark,U+203A ISO proposed -->
    348        // <!-- rsaquo is proposed but not yet ISO standardized -->
    349        initialMap.put("\u20AC", "&euro;"); // -- euro sign, U+20AC NEW -->
    350        HTML40_EXTENDED_ESCAPE = Collections.unmodifiableMap(initialMap);
    351    }
    352
    353    /**
    354     * Reverse of {@link #HTML40_EXTENDED_ESCAPE} for unescaping purposes.
    355     */
    356    public static final Map<CharSequence, CharSequence> HTML40_EXTENDED_UNESCAPE;
    357    static {
    358        HTML40_EXTENDED_UNESCAPE = Collections.unmodifiableMap(invert(HTML40_EXTENDED_ESCAPE));
    359    }
    360
    361    /**
    362     * A Map&lt;CharSequence, CharSequence&gt; to escape the basic XML and HTML
    363     * character entities.
    364     *
    365     * Namely: {@code " & < >}
    366     */
    367    public static final Map<CharSequence, CharSequence> BASIC_ESCAPE;
    368    static {
    369        final Map<CharSequence, CharSequence> initialMap = new HashMap<>();
    370        initialMap.put("\"", "&quot;"); // " - double-quote
    371        initialMap.put("&", "&amp;");   // & - ampersand
    372        initialMap.put("<", "&lt;");    // < - less-than
    373        initialMap.put(">", "&gt;");    // > - greater-than
    374        BASIC_ESCAPE = Collections.unmodifiableMap(initialMap);
    375    }
    376
    377    /**
    378     * Reverse of {@link #BASIC_ESCAPE} for unescaping purposes.
    379     */
    380    public static final Map<CharSequence, CharSequence> BASIC_UNESCAPE;
    381    static {
    382        BASIC_UNESCAPE = Collections.unmodifiableMap(invert(BASIC_ESCAPE));
    383    }
    384
    385    /**
    386     * A Map&lt;CharSequence, CharSequence&gt; to escape the apostrophe character to
    387     * its XML character entity.
    388     */
    389    public static final Map<CharSequence, CharSequence> APOS_ESCAPE;
    390    static {
    391        final Map<CharSequence, CharSequence> initialMap = new HashMap<>();
    392        initialMap.put("'", "&apos;"); // XML apostrophe
    393        APOS_ESCAPE = Collections.unmodifiableMap(initialMap);
    394    }
    395
    396    /**
    397     * Reverse of {@link #APOS_ESCAPE} for unescaping purposes.
    398     */
    399    public static final Map<CharSequence, CharSequence> APOS_UNESCAPE;
    400    static {
    401        APOS_UNESCAPE = Collections.unmodifiableMap(invert(APOS_ESCAPE));
    402    }
    403
    404    /**
    405     * A Map&lt;CharSequence, CharSequence&gt; to escape the Java
    406     * control characters.
    407     *
    408     * Namely: {@code \b \n \t \f \r}
    409     */
    410    public static final Map<CharSequence, CharSequence> JAVA_CTRL_CHARS_ESCAPE;
    411    static {
    412        final Map<CharSequence, CharSequence> initialMap = new HashMap<>();
    413        initialMap.put("\b", "\\b");
    414        initialMap.put("\n", "\\n");
    415        initialMap.put("\t", "\\t");
    416        initialMap.put("\f", "\\f");
    417        initialMap.put("\r", "\\r");
    418        JAVA_CTRL_CHARS_ESCAPE = Collections.unmodifiableMap(initialMap);
    419    }
    420
    421    /**
    422     * Reverse of {@link #JAVA_CTRL_CHARS_ESCAPE} for unescaping purposes.
    423     */
    424    public static final Map<CharSequence, CharSequence> JAVA_CTRL_CHARS_UNESCAPE;
    425    static {
    426        JAVA_CTRL_CHARS_UNESCAPE = Collections.unmodifiableMap(invert(JAVA_CTRL_CHARS_ESCAPE));
    427    }
    428
    429    /**
    430     * Used to invert an escape Map into an unescape Map.
    431     * @param map Map&lt;String, String&gt; to be inverted
    432     * @return Map&lt;String, String&gt; inverted array
    433     */
    434    public static Map<CharSequence, CharSequence> invert(final Map<CharSequence, CharSequence> map) {
    435        final Map<CharSequence, CharSequence> newMap = new HashMap<>();
    436        for (final Map.Entry<CharSequence, CharSequence> pair : map.entrySet()) {
    437            newMap.put(pair.getValue(), pair.getKey());
    438        }
    439        return newMap;
    440    }
    441
    442}