Java Code Examples for com.sun.org.apache.xerces.internal.util.XMLChar#supplemental()
The following examples show how to use
com.sun.org.apache.xerces.internal.util.XMLChar#supplemental() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XMLScanner.java From Bytecoder with Apache License 2.0 | 5 votes |
/** * Scans surrogates and append them to the specified buffer. * <p> * <strong>Note:</strong> This assumes the current char has already been * identified as a high surrogate. * * @param buf The StringBuffer to append the read surrogates to. * @return True if it succeeded. */ protected boolean scanSurrogates(XMLStringBuffer buf) throws IOException, XNIException { int high = fEntityScanner.scanChar(null); int low = fEntityScanner.peekChar(); if (!XMLChar.isLowSurrogate(low)) { reportFatalError("InvalidCharInContent", new Object[] {Integer.toString(high, 16)}); return false; } fEntityScanner.scanChar(null); // convert surrogates to supplemental character int c = XMLChar.supplemental((char)high, (char)low); // supplemental character must be a valid XML character if (isInvalid(c)) { reportFatalError("InvalidCharInContent", new Object[]{Integer.toString(c, 16)}); return false; } // fill in the buffer buf.append((char)high); buf.append((char)low); return true; }
Example 2
Source File: BaseMarkupSerializer.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
protected void surrogates(int high, int low, boolean inContent) throws IOException{ if (XMLChar.isHighSurrogate(high)) { if (!XMLChar.isLowSurrogate(low)) { //Invalid XML fatalError("The character '"+(char)low+"' is an invalid XML character"); } else { int supplemental = XMLChar.supplemental((char)high, (char)low); if (!XMLChar.isValid(supplemental)) { //Invalid XML fatalError("The character '"+(char)supplemental+"' is an invalid XML character"); } else { if (inContent && content().inCData) { _printer.printText("]]>&#x"); _printer.printText(Integer.toHexString(supplemental)); _printer.printText(";<![CDATA["); } else { printHex(supplemental); } } } } else { fatalError("The character '"+(char)high+"' is an invalid XML character"); } }
Example 3
Source File: XML11Serializer.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
protected final void surrogates(int high, int low) throws IOException{ if (XMLChar.isHighSurrogate(high)) { if (!XMLChar.isLowSurrogate(low)) { //Invalid XML fatalError("The character '"+(char)low+"' is an invalid XML character"); } else { int supplemental = XMLChar.supplemental((char)high, (char)low); if (!XML11Char.isXML11Valid(supplemental)) { //Invalid XML fatalError("The character '"+(char)supplemental+"' is an invalid XML character"); } else { if (content().inCData ) { _printer.printText("]]>&#x"); _printer.printText(Integer.toHexString(supplemental)); _printer.printText(";<![CDATA["); } else { printHex(supplemental); } } } } else { fatalError("The character '"+(char)high+"' is an invalid XML character"); } }
Example 4
Source File: BaseMarkupSerializer.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
protected void surrogates(int high, int low) throws IOException{ if (XMLChar.isHighSurrogate(high)) { if (!XMLChar.isLowSurrogate(low)) { //Invalid XML fatalError("The character '"+(char)low+"' is an invalid XML character"); } else { int supplemental = XMLChar.supplemental((char)high, (char)low); if (!XMLChar.isValid(supplemental)) { //Invalid XML fatalError("The character '"+(char)supplemental+"' is an invalid XML character"); } else { if (content().inCData ) { _printer.printText("]]>&#x"); _printer.printText(Integer.toHexString(supplemental)); _printer.printText(";<![CDATA["); } else { printHex(supplemental); } } } } else { fatalError("The character '"+(char)high+"' is an invalid XML character"); } }
Example 5
Source File: BaseMarkupSerializer.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
protected void surrogates(int high, int low) throws IOException{ if (XMLChar.isHighSurrogate(high)) { if (!XMLChar.isLowSurrogate(low)) { //Invalid XML fatalError("The character '"+(char)low+"' is an invalid XML character"); } else { int supplemental = XMLChar.supplemental((char)high, (char)low); if (!XMLChar.isValid(supplemental)) { //Invalid XML fatalError("The character '"+(char)supplemental+"' is an invalid XML character"); } else { if (content().inCData ) { _printer.printText("]]>&#x"); _printer.printText(Integer.toHexString(supplemental)); _printer.printText(";<![CDATA["); } else { printHex(supplemental); } } } } else { fatalError("The character '"+(char)high+"' is an invalid XML character"); } }
Example 6
Source File: BaseMarkupSerializer.java From hottub with GNU General Public License v2.0 | 5 votes |
protected void surrogates(int high, int low) throws IOException{ if (XMLChar.isHighSurrogate(high)) { if (!XMLChar.isLowSurrogate(low)) { //Invalid XML fatalError("The character '"+(char)low+"' is an invalid XML character"); } else { int supplemental = XMLChar.supplemental((char)high, (char)low); if (!XMLChar.isValid(supplemental)) { //Invalid XML fatalError("The character '"+(char)supplemental+"' is an invalid XML character"); } else { if (content().inCData ) { _printer.printText("]]>&#x"); _printer.printText(Integer.toHexString(supplemental)); _printer.printText(";<![CDATA["); } else { printHex(supplemental); } } } } else { fatalError("The character '"+(char)high+"' is an invalid XML character"); } }
Example 7
Source File: XML11Serializer.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
protected final void surrogates(int high, int low, boolean inContent) throws IOException{ if (XMLChar.isHighSurrogate(high)) { if (!XMLChar.isLowSurrogate(low)) { //Invalid XML fatalError("The character '"+(char)low+"' is an invalid XML character"); } else { int supplemental = XMLChar.supplemental((char)high, (char)low); if (!XML11Char.isXML11Valid(supplemental)) { //Invalid XML fatalError("The character '"+(char)supplemental+"' is an invalid XML character"); } else { if (inContent && content().inCData) { _printer.printText("]]>&#x"); _printer.printText(Integer.toHexString(supplemental)); _printer.printText(";<![CDATA["); } else { printHex(supplemental); } } } } else { fatalError("The character '"+(char)high+"' is an invalid XML character"); } }
Example 8
Source File: XMLScanner.java From JDKSourceCode1.8 with MIT License | 5 votes |
/** * Scans surrogates and append them to the specified buffer. * <p> * <strong>Note:</strong> This assumes the current char has already been * identified as a high surrogate. * * @param buf The StringBuffer to append the read surrogates to. * @return True if it succeeded. */ protected boolean scanSurrogates(XMLStringBuffer buf) throws IOException, XNIException { int high = fEntityScanner.scanChar(null); int low = fEntityScanner.peekChar(); if (!XMLChar.isLowSurrogate(low)) { reportFatalError("InvalidCharInContent", new Object[] {Integer.toString(high, 16)}); return false; } fEntityScanner.scanChar(null); // convert surrogates to supplemental character int c = XMLChar.supplemental((char)high, (char)low); // supplemental character must be a valid XML character if (isInvalid(c)) { reportFatalError("InvalidCharInContent", new Object[]{Integer.toString(c, 16)}); return false; } // fill in the buffer buf.append((char)high); buf.append((char)low); return true; }
Example 9
Source File: BaseMarkupSerializer.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
protected void surrogates(int high, int low) throws IOException{ if (XMLChar.isHighSurrogate(high)) { if (!XMLChar.isLowSurrogate(low)) { //Invalid XML fatalError("The character '"+(char)low+"' is an invalid XML character"); } else { int supplemental = XMLChar.supplemental((char)high, (char)low); if (!XMLChar.isValid(supplemental)) { //Invalid XML fatalError("The character '"+(char)supplemental+"' is an invalid XML character"); } else { if (content().inCData ) { _printer.printText("]]>&#x"); _printer.printText(Integer.toHexString(supplemental)); _printer.printText(";<![CDATA["); } else { printHex(supplemental); } } } } else { fatalError("The character '"+(char)high+"' is an invalid XML character"); } }
Example 10
Source File: XMLScanner.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * Scans surrogates and append them to the specified buffer. * <p> * <strong>Note:</strong> This assumes the current char has already been * identified as a high surrogate. * * @param buf The StringBuffer to append the read surrogates to. * @return True if it succeeded. */ protected boolean scanSurrogates(XMLStringBuffer buf) throws IOException, XNIException { int high = fEntityScanner.scanChar(); int low = fEntityScanner.peekChar(); if (!XMLChar.isLowSurrogate(low)) { reportFatalError("InvalidCharInContent", new Object[] {Integer.toString(high, 16)}); return false; } fEntityScanner.scanChar(); // convert surrogates to supplemental character int c = XMLChar.supplemental((char)high, (char)low); // supplemental character must be a valid XML character if (isInvalid(c)) { reportFatalError("InvalidCharInContent", new Object[]{Integer.toString(c, 16)}); return false; } // fill in the buffer buf.append((char)high); buf.append((char)low); return true; }
Example 11
Source File: XMLScanner.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** * Scans surrogates and append them to the specified buffer. * <p> * <strong>Note:</strong> This assumes the current char has already been * identified as a high surrogate. * * @param buf The StringBuffer to append the read surrogates to. * @return True if it succeeded. */ protected boolean scanSurrogates(XMLStringBuffer buf) throws IOException, XNIException { int high = fEntityScanner.scanChar(); int low = fEntityScanner.peekChar(); if (!XMLChar.isLowSurrogate(low)) { reportFatalError("InvalidCharInContent", new Object[] {Integer.toString(high, 16)}); return false; } fEntityScanner.scanChar(); // convert surrogates to supplemental character int c = XMLChar.supplemental((char)high, (char)low); // supplemental character must be a valid XML character if (isInvalid(c)) { reportFatalError("InvalidCharInContent", new Object[]{Integer.toString(c, 16)}); return false; } // fill in the buffer buf.append((char)high); buf.append((char)low); return true; }
Example 12
Source File: BaseMarkupSerializer.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
protected void surrogates(int high, int low) throws IOException{ if (XMLChar.isHighSurrogate(high)) { if (!XMLChar.isLowSurrogate(low)) { //Invalid XML fatalError("The character '"+(char)low+"' is an invalid XML character"); } else { int supplemental = XMLChar.supplemental((char)high, (char)low); if (!XMLChar.isValid(supplemental)) { //Invalid XML fatalError("The character '"+(char)supplemental+"' is an invalid XML character"); } else { if (content().inCData ) { _printer.printText("]]>&#x"); _printer.printText(Integer.toHexString(supplemental)); _printer.printText(";<![CDATA["); } else { printHex(supplemental); } } } } else { fatalError("The character '"+(char)high+"' is an invalid XML character"); } }
Example 13
Source File: XML11Serializer.java From hottub with GNU General Public License v2.0 | 5 votes |
protected final void surrogates(int high, int low) throws IOException{ if (XMLChar.isHighSurrogate(high)) { if (!XMLChar.isLowSurrogate(low)) { //Invalid XML fatalError("The character '"+(char)low+"' is an invalid XML character"); } else { int supplemental = XMLChar.supplemental((char)high, (char)low); if (!XML11Char.isXML11Valid(supplemental)) { //Invalid XML fatalError("The character '"+(char)supplemental+"' is an invalid XML character"); } else { if (content().inCData ) { _printer.printText("]]>&#x"); _printer.printText(Integer.toHexString(supplemental)); _printer.printText(";<![CDATA["); } else { printHex(supplemental); } } } } else { fatalError("The character '"+(char)high+"' is an invalid XML character"); } }
Example 14
Source File: BaseMarkupSerializer.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
protected void surrogates(int high, int low) throws IOException{ if (XMLChar.isHighSurrogate(high)) { if (!XMLChar.isLowSurrogate(low)) { //Invalid XML fatalError("The character '"+(char)low+"' is an invalid XML character"); } else { int supplemental = XMLChar.supplemental((char)high, (char)low); if (!XMLChar.isValid(supplemental)) { //Invalid XML fatalError("The character '"+(char)supplemental+"' is an invalid XML character"); } else { if (content().inCData ) { _printer.printText("]]>&#x"); _printer.printText(Integer.toHexString(supplemental)); _printer.printText(";<![CDATA["); } else { printHex(supplemental); } } } } else { fatalError("The character '"+(char)high+"' is an invalid XML character"); } }
Example 15
Source File: XML11Serializer.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
protected final void surrogates(int high, int low) throws IOException{ if (XMLChar.isHighSurrogate(high)) { if (!XMLChar.isLowSurrogate(low)) { //Invalid XML fatalError("The character '"+(char)low+"' is an invalid XML character"); } else { int supplemental = XMLChar.supplemental((char)high, (char)low); if (!XML11Char.isXML11Valid(supplemental)) { //Invalid XML fatalError("The character '"+(char)supplemental+"' is an invalid XML character"); } else { if (content().inCData ) { _printer.printText("]]>&#x"); _printer.printText(Integer.toHexString(supplemental)); _printer.printText(";<![CDATA["); } else { printHex(supplemental); } } } } else { fatalError("The character '"+(char)high+"' is an invalid XML character"); } }
Example 16
Source File: XIncludeHandler.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
private String escapeHref(String href) { int len = href.length(); int ch; final StringBuilder buffer = new StringBuilder(len*3); // for each character in the href int i = 0; for (; i < len; i++) { ch = href.charAt(i); // if it's not an ASCII character (excluding 0x7F), break here, and use UTF-8 encoding if (ch > 0x7E) { break; } // abort: href does not allow this character if (ch < 0x20) { return href; } if (gNeedEscaping[ch]) { buffer.append('%'); buffer.append(gAfterEscaping1[ch]); buffer.append(gAfterEscaping2[ch]); } else { buffer.append((char)ch); } } // we saw some non-ascii character if (i < len) { // check if remainder of href contains any illegal characters before proceeding for (int j = i; j < len; ++j) { ch = href.charAt(j); if ((ch >= 0x20 && ch <= 0x7E) || (ch >= 0xA0 && ch <= 0xD7FF) || (ch >= 0xF900 && ch <= 0xFDCF) || (ch >= 0xFDF0 && ch <= 0xFFEF)) { continue; } if (XMLChar.isHighSurrogate(ch) && ++j < len) { int ch2 = href.charAt(j); if (XMLChar.isLowSurrogate(ch2)) { ch2 = XMLChar.supplemental((char)ch, (char)ch2); if (ch2 < 0xF0000 && (ch2 & 0xFFFF) <= 0xFFFD) { continue; } } } // abort: href does not allow this character return href; } // get UTF-8 bytes for the remaining sub-string byte[] bytes = null; byte b; try { bytes = href.substring(i).getBytes("UTF-8"); } catch (java.io.UnsupportedEncodingException e) { // should never happen return href; } len = bytes.length; // for each byte for (i = 0; i < len; i++) { b = bytes[i]; // for non-ascii character: make it positive, then escape if (b < 0) { ch = b + 256; buffer.append('%'); buffer.append(gHexChs[ch >> 4]); buffer.append(gHexChs[ch & 0xf]); } else if (gNeedEscaping[b]) { buffer.append('%'); buffer.append(gAfterEscaping1[b]); buffer.append(gAfterEscaping2[b]); } else { buffer.append((char)b); } } } // If escaping happened, create a new string; // otherwise, return the orginal one. if (buffer.length() != len) { return buffer.toString(); } else { return href; } }
Example 17
Source File: XIncludeHandler.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
private String escapeHref(String href) { int len = href.length(); int ch; final StringBuilder buffer = new StringBuilder(len*3); // for each character in the href int i = 0; for (; i < len; i++) { ch = href.charAt(i); // if it's not an ASCII character (excluding 0x7F), break here, and use UTF-8 encoding if (ch > 0x7E) { break; } // abort: href does not allow this character if (ch < 0x20) { return href; } if (gNeedEscaping[ch]) { buffer.append('%'); buffer.append(gAfterEscaping1[ch]); buffer.append(gAfterEscaping2[ch]); } else { buffer.append((char)ch); } } // we saw some non-ascii character if (i < len) { // check if remainder of href contains any illegal characters before proceeding for (int j = i; j < len; ++j) { ch = href.charAt(j); if ((ch >= 0x20 && ch <= 0x7E) || (ch >= 0xA0 && ch <= 0xD7FF) || (ch >= 0xF900 && ch <= 0xFDCF) || (ch >= 0xFDF0 && ch <= 0xFFEF)) { continue; } if (XMLChar.isHighSurrogate(ch) && ++j < len) { int ch2 = href.charAt(j); if (XMLChar.isLowSurrogate(ch2)) { ch2 = XMLChar.supplemental((char)ch, (char)ch2); if (ch2 < 0xF0000 && (ch2 & 0xFFFF) <= 0xFFFD) { continue; } } } // abort: href does not allow this character return href; } // get UTF-8 bytes for the remaining sub-string byte[] bytes = null; byte b; try { bytes = href.substring(i).getBytes("UTF-8"); } catch (java.io.UnsupportedEncodingException e) { // should never happen return href; } len = bytes.length; // for each byte for (i = 0; i < len; i++) { b = bytes[i]; // for non-ascii character: make it positive, then escape if (b < 0) { ch = b + 256; buffer.append('%'); buffer.append(gHexChs[ch >> 4]); buffer.append(gHexChs[ch & 0xf]); } else if (gNeedEscaping[b]) { buffer.append('%'); buffer.append(gAfterEscaping1[b]); buffer.append(gAfterEscaping2[b]); } else { buffer.append((char)b); } } } // If escaping happened, create a new string; // otherwise, return the orginal one. if (buffer.length() != len) { return buffer.toString(); } else { return href; } }
Example 18
Source File: XIncludeHandler.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
private String escapeHref(String href) { int len = href.length(); int ch; final StringBuilder buffer = new StringBuilder(len*3); // for each character in the href int i = 0; for (; i < len; i++) { ch = href.charAt(i); // if it's not an ASCII character (excluding 0x7F), break here, and use UTF-8 encoding if (ch > 0x7E) { break; } // abort: href does not allow this character if (ch < 0x20) { return href; } if (gNeedEscaping[ch]) { buffer.append('%'); buffer.append(gAfterEscaping1[ch]); buffer.append(gAfterEscaping2[ch]); } else { buffer.append((char)ch); } } // we saw some non-ascii character if (i < len) { // check if remainder of href contains any illegal characters before proceeding for (int j = i; j < len; ++j) { ch = href.charAt(j); if ((ch >= 0x20 && ch <= 0x7E) || (ch >= 0xA0 && ch <= 0xD7FF) || (ch >= 0xF900 && ch <= 0xFDCF) || (ch >= 0xFDF0 && ch <= 0xFFEF)) { continue; } if (XMLChar.isHighSurrogate(ch) && ++j < len) { int ch2 = href.charAt(j); if (XMLChar.isLowSurrogate(ch2)) { ch2 = XMLChar.supplemental((char)ch, (char)ch2); if (ch2 < 0xF0000 && (ch2 & 0xFFFF) <= 0xFFFD) { continue; } } } // abort: href does not allow this character return href; } // get UTF-8 bytes for the remaining sub-string byte[] bytes = null; byte b; try { bytes = href.substring(i).getBytes("UTF-8"); } catch (java.io.UnsupportedEncodingException e) { // should never happen return href; } len = bytes.length; // for each byte for (i = 0; i < len; i++) { b = bytes[i]; // for non-ascii character: make it positive, then escape if (b < 0) { ch = b + 256; buffer.append('%'); buffer.append(gHexChs[ch >> 4]); buffer.append(gHexChs[ch & 0xf]); } else if (gNeedEscaping[b]) { buffer.append('%'); buffer.append(gAfterEscaping1[b]); buffer.append(gAfterEscaping2[b]); } else { buffer.append((char)b); } } } // If escaping happened, create a new string; // otherwise, return the orginal one. if (buffer.length() != len) { return buffer.toString(); } else { return href; } }
Example 19
Source File: XIncludeHandler.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
private String escapeHref(String href) { int len = href.length(); int ch; final StringBuilder buffer = new StringBuilder(len*3); // for each character in the href int i = 0; for (; i < len; i++) { ch = href.charAt(i); // if it's not an ASCII character (excluding 0x7F), break here, and use UTF-8 encoding if (ch > 0x7E) { break; } // abort: href does not allow this character if (ch < 0x20) { return href; } if (gNeedEscaping[ch]) { buffer.append('%'); buffer.append(gAfterEscaping1[ch]); buffer.append(gAfterEscaping2[ch]); } else { buffer.append((char)ch); } } // we saw some non-ascii character if (i < len) { // check if remainder of href contains any illegal characters before proceeding for (int j = i; j < len; ++j) { ch = href.charAt(j); if ((ch >= 0x20 && ch <= 0x7E) || (ch >= 0xA0 && ch <= 0xD7FF) || (ch >= 0xF900 && ch <= 0xFDCF) || (ch >= 0xFDF0 && ch <= 0xFFEF)) { continue; } if (XMLChar.isHighSurrogate(ch) && ++j < len) { int ch2 = href.charAt(j); if (XMLChar.isLowSurrogate(ch2)) { ch2 = XMLChar.supplemental((char)ch, (char)ch2); if (ch2 < 0xF0000 && (ch2 & 0xFFFF) <= 0xFFFD) { continue; } } } // abort: href does not allow this character return href; } // get UTF-8 bytes for the remaining sub-string byte[] bytes = null; byte b; try { bytes = href.substring(i).getBytes("UTF-8"); } catch (java.io.UnsupportedEncodingException e) { // should never happen return href; } len = bytes.length; // for each byte for (i = 0; i < len; i++) { b = bytes[i]; // for non-ascii character: make it positive, then escape if (b < 0) { ch = b + 256; buffer.append('%'); buffer.append(gHexChs[ch >> 4]); buffer.append(gHexChs[ch & 0xf]); } else if (gNeedEscaping[b]) { buffer.append('%'); buffer.append(gAfterEscaping1[b]); buffer.append(gAfterEscaping2[b]); } else { buffer.append((char)b); } } } // If escaping happened, create a new string; // otherwise, return the orginal one. if (buffer.length() != len) { return buffer.toString(); } else { return href; } }
Example 20
Source File: XIncludeHandler.java From jdk1.8-source-analysis with Apache License 2.0 | 4 votes |
private String escapeHref(String href) { int len = href.length(); int ch; final StringBuilder buffer = new StringBuilder(len*3); // for each character in the href int i = 0; for (; i < len; i++) { ch = href.charAt(i); // if it's not an ASCII character (excluding 0x7F), break here, and use UTF-8 encoding if (ch > 0x7E) { break; } // abort: href does not allow this character if (ch < 0x20) { return href; } if (gNeedEscaping[ch]) { buffer.append('%'); buffer.append(gAfterEscaping1[ch]); buffer.append(gAfterEscaping2[ch]); } else { buffer.append((char)ch); } } // we saw some non-ascii character if (i < len) { // check if remainder of href contains any illegal characters before proceeding for (int j = i; j < len; ++j) { ch = href.charAt(j); if ((ch >= 0x20 && ch <= 0x7E) || (ch >= 0xA0 && ch <= 0xD7FF) || (ch >= 0xF900 && ch <= 0xFDCF) || (ch >= 0xFDF0 && ch <= 0xFFEF)) { continue; } if (XMLChar.isHighSurrogate(ch) && ++j < len) { int ch2 = href.charAt(j); if (XMLChar.isLowSurrogate(ch2)) { ch2 = XMLChar.supplemental((char)ch, (char)ch2); if (ch2 < 0xF0000 && (ch2 & 0xFFFF) <= 0xFFFD) { continue; } } } // abort: href does not allow this character return href; } // get UTF-8 bytes for the remaining sub-string byte[] bytes = null; byte b; try { bytes = href.substring(i).getBytes("UTF-8"); } catch (java.io.UnsupportedEncodingException e) { // should never happen return href; } len = bytes.length; // for each byte for (i = 0; i < len; i++) { b = bytes[i]; // for non-ascii character: make it positive, then escape if (b < 0) { ch = b + 256; buffer.append('%'); buffer.append(gHexChs[ch >> 4]); buffer.append(gHexChs[ch & 0xf]); } else if (gNeedEscaping[b]) { buffer.append('%'); buffer.append(gAfterEscaping1[b]); buffer.append(gAfterEscaping2[b]); } else { buffer.append((char)b); } } } // If escaping happened, create a new string; // otherwise, return the orginal one. if (buffer.length() != len) { return buffer.toString(); } else { return href; } }