feat(jdk8): move files to new folder to avoid resources compiled.
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.codemodel.internal.util;
|
||||
|
||||
import java.util.Comparator;
|
||||
import com.sun.codemodel.internal.JClass;
|
||||
|
||||
/**
|
||||
* Comparator object that sorts {@link JClass}es in the order
|
||||
* of their names.
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
public class ClassNameComparator implements Comparator<JClass> {
|
||||
private ClassNameComparator() {}
|
||||
|
||||
public int compare(JClass l, JClass r) {
|
||||
return l.fullName().compareTo(r.fullName());
|
||||
}
|
||||
|
||||
public static final Comparator<JClass> theInstance = new ClassNameComparator();
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @(#)$Id: EncoderFactory.java,v 1.3 2005/09/10 19:07:33 kohsuke Exp $
|
||||
*/
|
||||
package com.sun.codemodel.internal.util;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.CharsetEncoder;
|
||||
|
||||
/**
|
||||
* Creates {@link CharsetEncoder} from a charset name.
|
||||
*
|
||||
* Fixes a MS1252 handling bug in JDK1.4.2.
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
public class EncoderFactory {
|
||||
|
||||
public static CharsetEncoder createEncoder( String encodin ) {
|
||||
Charset cs = Charset.forName(System.getProperty("file.encoding"));
|
||||
CharsetEncoder encoder = cs.newEncoder();
|
||||
|
||||
if( cs.getClass().getName().equals("sun.nio.cs.MS1252") ) {
|
||||
try {
|
||||
// at least JDK1.4.2_01 has a bug in MS1252 encoder.
|
||||
// specifically, it returns true for any character.
|
||||
// return a correct encoder to workaround this problem
|
||||
|
||||
// statically binding to MS1252Encoder will cause a Link error
|
||||
// (at least in IBM JDK1.4.1)
|
||||
@SuppressWarnings("unchecked")
|
||||
Class<? extends CharsetEncoder> ms1252encoder = (Class<? extends CharsetEncoder>) Class.forName("com.sun.codemodel.internal.util.MS1252Encoder");
|
||||
Constructor<? extends CharsetEncoder> c = ms1252encoder.getConstructor(new Class[]{
|
||||
Charset.class
|
||||
});
|
||||
return c.newInstance(new Object[]{cs});
|
||||
} catch( Throwable t ) {
|
||||
// if something funny happens, ignore it and fall back to
|
||||
// a broken MS1252 encoder. It's probably still better
|
||||
// than choking here.
|
||||
return encoder;
|
||||
}
|
||||
}
|
||||
|
||||
return encoder;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.codemodel.internal.util;
|
||||
|
||||
import java.io.FilterWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
|
||||
/**
|
||||
* {@link Writer} that escapes characters that are unsafe
|
||||
* as Javadoc comments.
|
||||
*
|
||||
* Such characters include '<' and '&'.
|
||||
*
|
||||
* <p>
|
||||
* Note that this class doesn't escape other Unicode characters
|
||||
* that are typically unsafe. For example, 愛 (A kanji
|
||||
* that means "love") can be considered as unsafe because
|
||||
* javac with English Windows cannot accept this character in the
|
||||
* source code.
|
||||
*
|
||||
* <p>
|
||||
* If the application needs to escape such characters as well, then
|
||||
* they are on their own.
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
public class JavadocEscapeWriter extends FilterWriter {
|
||||
|
||||
public JavadocEscapeWriter( Writer next ) {
|
||||
super(next);
|
||||
}
|
||||
|
||||
public void write(int ch) throws IOException {
|
||||
if(ch=='<')
|
||||
out.write("<");
|
||||
else
|
||||
if(ch=='&')
|
||||
out.write("&");
|
||||
else
|
||||
out.write(ch);
|
||||
}
|
||||
|
||||
public void write(char[] buf, int off, int len) throws IOException {
|
||||
for( int i=0; i<len; i++ )
|
||||
write(buf[off+i]);
|
||||
}
|
||||
|
||||
public void write(char[] buf) throws IOException {
|
||||
write(buf,0,buf.length);
|
||||
}
|
||||
|
||||
public void write(String buf, int off, int len) throws IOException {
|
||||
write( buf.toCharArray(), off, len );
|
||||
}
|
||||
|
||||
public void write(String buf) throws IOException {
|
||||
write( buf.toCharArray(), 0, buf.length() );
|
||||
}
|
||||
|
||||
}
|
||||
223
jdkSrc/jdk8/com/sun/codemodel/internal/util/MS1252Encoder.java
Normal file
223
jdkSrc/jdk8/com/sun/codemodel/internal/util/MS1252Encoder.java
Normal file
@@ -0,0 +1,223 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @(#)$Id: MS1252Encoder.java,v 1.2 2005/09/10 19:07:33 kohsuke Exp $
|
||||
*/
|
||||
package com.sun.codemodel.internal.util;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
/**
|
||||
* MS1252 encoder that corrects a bug in JDK1.4.2_01.
|
||||
*
|
||||
* <p>
|
||||
* See
|
||||
* http://www.microsoft.com/globaldev/reference/sbcs/1252.htm
|
||||
* for the normative definition.
|
||||
*
|
||||
* This code depends on Sun internal package, so we have to make sure
|
||||
* it won't be executed on other JDKs.
|
||||
*/
|
||||
public final class MS1252Encoder extends SingleByteEncoder {
|
||||
|
||||
public MS1252Encoder(Charset cs) {
|
||||
super(cs, index1, index2, 0xFF00, 0x00FF, 8);
|
||||
}
|
||||
|
||||
private final static String index2 =
|
||||
"\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007" +
|
||||
"\b\t\n\u000B\f\r\u000E\u000F" +
|
||||
"\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017" +
|
||||
"\u0018\u0019\u001A\u001B\u001C\u001D\u001E\u001F" +
|
||||
"\u0020\u0021\"\u0023\u0024\u0025\u0026\'" +
|
||||
"\u0028\u0029\u002A\u002B\u002C\u002D\u002E\u002F" +
|
||||
"\u0030\u0031\u0032\u0033\u0034\u0035\u0036\u0037" +
|
||||
"\u0038\u0039\u003A\u003B\u003C\u003D\u003E\u003F" +
|
||||
"\u0040\u0041\u0042\u0043\u0044\u0045\u0046\u0047" +
|
||||
"\u0048\u0049\u004A\u004B\u004C\u004D\u004E\u004F" +
|
||||
"\u0050\u0051\u0052\u0053\u0054\u0055\u0056\u0057" +
|
||||
"\u0058\u0059\u005A\u005B\\\u005D\u005E\u005F" +
|
||||
"\u0060\u0061\u0062\u0063\u0064\u0065\u0066\u0067" +
|
||||
"\u0068\u0069\u006A\u006B\u006C\u006D\u006E\u006F" +
|
||||
"\u0070\u0071\u0072\u0073\u0074\u0075\u0076\u0077" +
|
||||
"\u0078\u0079\u007A\u007B\u007C\u007D\u007E\u007F" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u00A0\u00A1\u00A2\u00A3\u00A4\u00A5\u00A6\u00A7" +
|
||||
"\u00A8\u00A9\u00AA\u00AB\u00AC\u00AD\u00AE\u00AF" +
|
||||
"\u00B0\u00B1\u00B2\u00B3\u00B4\u00B5\u00B6\u00B7" +
|
||||
"\u00B8\u00B9\u00BA\u00BB\u00BC\u00BD\u00BE\u00BF" +
|
||||
"\u00C0\u00C1\u00C2\u00C3\u00C4\u00C5\u00C6\u00C7" +
|
||||
"\u00C8\u00C9\u00CA\u00CB\u00CC\u00CD\u00CE\u00CF" +
|
||||
"\u00D0\u00D1\u00D2\u00D3\u00D4\u00D5\u00D6\u00D7" +
|
||||
"\u00D8\u00D9\u00DA\u00DB\u00DC\u00DD\u00DE\u00DF" +
|
||||
"\u00E0\u00E1\u00E2\u00E3\u00E4\u00E5\u00E6\u00E7" +
|
||||
"\u00E8\u00E9\u00EA\u00EB\u00EC\u00ED\u00EE\u00EF" +
|
||||
"\u00F0\u00F1\u00F2\u00F3\u00F4\u00F5\u00F6\u00F7" +
|
||||
"\u00F8\u00F9\u00FA\u00FB\u00FC\u00FD\u00FE\u00FF" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u008C\u009C\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u008A\u009A\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u009F\u0000\u0000\u0000\u0000\u008E\u009E\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0083\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0088\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0098\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0096\u0097\u0000" +
|
||||
"\u0000\u0000\u0091\u0092\u0082\u0000\u0093\u0094" +
|
||||
"\u0084\u0000\u0086\u0087\u0095\u0000\u0000\u0000" +
|
||||
"\u0085\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0089\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u008B\u009B\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0080\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0099\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000";
|
||||
|
||||
private final static short index1[] = {
|
||||
0, 256, 461, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403,
|
||||
403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403,
|
||||
698, 920, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403,
|
||||
403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403,
|
||||
403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403,
|
||||
403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403,
|
||||
403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403,
|
||||
403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403,
|
||||
403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403,
|
||||
403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403,
|
||||
403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403,
|
||||
403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403,
|
||||
403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403,
|
||||
403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403,
|
||||
403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403,
|
||||
403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403,
|
||||
};
|
||||
|
||||
public boolean canEncode(char c) {
|
||||
char test = index2.charAt( index1[(c&0xFF00)>>8] + (c&0xFF) );
|
||||
return test!=0;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @(#)SingleByteEncoder.java 1.14 03/01/23
|
||||
*/
|
||||
|
||||
package com.sun.codemodel.internal.util;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.CharBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.CharsetEncoder;
|
||||
import java.nio.charset.CoderResult;
|
||||
|
||||
import sun.nio.cs.Surrogate;
|
||||
|
||||
|
||||
abstract class SingleByteEncoder
|
||||
extends CharsetEncoder
|
||||
{
|
||||
|
||||
private final short index1[];
|
||||
private final String index2;
|
||||
private final int mask1;
|
||||
private final int mask2;
|
||||
private final int shift;
|
||||
|
||||
private final Surrogate.Parser sgp = new Surrogate.Parser();
|
||||
|
||||
protected SingleByteEncoder(Charset cs,
|
||||
short[] index1, String index2,
|
||||
int mask1, int mask2, int shift)
|
||||
{
|
||||
super(cs, 1.0f, 1.0f);
|
||||
this.index1 = index1;
|
||||
this.index2 = index2;
|
||||
this.mask1 = mask1;
|
||||
this.mask2 = mask2;
|
||||
this.shift = shift;
|
||||
}
|
||||
|
||||
public boolean canEncode(char c) {
|
||||
char testEncode;
|
||||
testEncode = index2.charAt(index1[(c & mask1) >> shift]
|
||||
+ (c & mask2));
|
||||
if (testEncode == '\u0000')
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
private CoderResult encodeArrayLoop(CharBuffer src, ByteBuffer dst) {
|
||||
char[] sa = src.array();
|
||||
int sp = src.arrayOffset() + src.position();
|
||||
int sl = src.arrayOffset() + src.limit();
|
||||
sp = (sp <= sl ? sp : sl);
|
||||
byte[] da = dst.array();
|
||||
int dp = dst.arrayOffset() + dst.position();
|
||||
int dl = dst.arrayOffset() + dst.limit();
|
||||
dp = (dp <= dl ? dp : dl);
|
||||
|
||||
try {
|
||||
while (sp < sl) {
|
||||
char c = sa[sp];
|
||||
if (Surrogate.is(c)) {
|
||||
if (sgp.parse(c, sa, sp, sl) < 0)
|
||||
return sgp.error();
|
||||
return sgp.unmappableResult();
|
||||
}
|
||||
if (c >= '\uFFFE')
|
||||
return CoderResult.unmappableForLength(1);
|
||||
if (dl - dp < 1)
|
||||
return CoderResult.OVERFLOW;
|
||||
|
||||
char e = index2.charAt(index1[(c & mask1) >> shift]
|
||||
+ (c & mask2));
|
||||
|
||||
// If output byte is zero because input char is zero
|
||||
// then character is mappable, o.w. fail
|
||||
if (e == '\u0000' && c != '\u0000')
|
||||
return CoderResult.unmappableForLength(1);
|
||||
|
||||
sp++;
|
||||
da[dp++] = (byte)e;
|
||||
}
|
||||
return CoderResult.UNDERFLOW;
|
||||
} finally {
|
||||
src.position(sp - src.arrayOffset());
|
||||
dst.position(dp - dst.arrayOffset());
|
||||
}
|
||||
}
|
||||
|
||||
private CoderResult encodeBufferLoop(CharBuffer src, ByteBuffer dst) {
|
||||
int mark = src.position();
|
||||
try {
|
||||
while (src.hasRemaining()) {
|
||||
char c = src.get();
|
||||
if (Surrogate.is(c)) {
|
||||
if (sgp.parse(c, src) < 0)
|
||||
return sgp.error();
|
||||
return sgp.unmappableResult();
|
||||
}
|
||||
if (c >= '\uFFFE')
|
||||
return CoderResult.unmappableForLength(1);
|
||||
if (!dst.hasRemaining())
|
||||
return CoderResult.OVERFLOW;
|
||||
|
||||
char e = index2.charAt(index1[(c & mask1) >> shift]
|
||||
+ (c & mask2));
|
||||
|
||||
// If output byte is zero because input char is zero
|
||||
// then character is mappable, o.w. fail
|
||||
if (e == '\u0000' && c != '\u0000')
|
||||
return CoderResult.unmappableForLength(1);
|
||||
|
||||
mark++;
|
||||
dst.put((byte)e);
|
||||
}
|
||||
return CoderResult.UNDERFLOW;
|
||||
} finally {
|
||||
src.position(mark);
|
||||
}
|
||||
}
|
||||
|
||||
protected CoderResult encodeLoop(CharBuffer src, ByteBuffer dst) {
|
||||
if (true && src.hasArray() && dst.hasArray())
|
||||
return encodeArrayLoop(src, dst);
|
||||
else
|
||||
return encodeBufferLoop(src, dst);
|
||||
}
|
||||
|
||||
public byte encode(char inputChar) {
|
||||
return (byte)index2.charAt(index1[(inputChar & mask1) >> shift] +
|
||||
(inputChar & mask2));
|
||||
}
|
||||
}
|
||||
355
jdkSrc/jdk8/com/sun/codemodel/internal/util/Surrogate.java
Normal file
355
jdkSrc/jdk8/com/sun/codemodel/internal/util/Surrogate.java
Normal file
@@ -0,0 +1,355 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.codemodel.internal.util;
|
||||
|
||||
import java.nio.CharBuffer;
|
||||
import java.nio.charset.CoderResult;
|
||||
|
||||
|
||||
/**
|
||||
* Utility class for dealing with surrogates.
|
||||
*
|
||||
* @author Mark Reinhold
|
||||
* @version 1.11, 03/01/23
|
||||
*/
|
||||
|
||||
class Surrogate {
|
||||
|
||||
private Surrogate() { }
|
||||
|
||||
// UTF-16 surrogate-character ranges
|
||||
//
|
||||
public static final char MIN_HIGH = '\uD800';
|
||||
public static final char MAX_HIGH = '\uDBFF';
|
||||
public static final char MIN_LOW = '\uDC00';
|
||||
public static final char MAX_LOW = '\uDFFF';
|
||||
public static final char MIN = MIN_HIGH;
|
||||
public static final char MAX = MAX_LOW;
|
||||
|
||||
// Range of UCS-4 values that need surrogates in UTF-16
|
||||
//
|
||||
public static final int UCS4_MIN = 0x10000;
|
||||
public static final int UCS4_MAX = (1 << 20) + UCS4_MIN - 1;
|
||||
|
||||
/**
|
||||
* Tells whether or not the given UTF-16 value is a high surrogate.
|
||||
*/
|
||||
public static boolean isHigh(int c) {
|
||||
return (MIN_HIGH <= c) && (c <= MAX_HIGH);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether or not the given UTF-16 value is a low surrogate.
|
||||
*/
|
||||
public static boolean isLow(int c) {
|
||||
return (MIN_LOW <= c) && (c <= MAX_LOW);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether or not the given UTF-16 value is a surrogate character,
|
||||
*/
|
||||
public static boolean is(int c) {
|
||||
return (MIN <= c) && (c <= MAX);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether or not the given UCS-4 character must be represented as a
|
||||
* surrogate pair in UTF-16.
|
||||
*/
|
||||
public static boolean neededFor(int uc) {
|
||||
return (uc >= UCS4_MIN) && (uc <= UCS4_MAX);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the high UTF-16 surrogate for the given UCS-4 character.
|
||||
*/
|
||||
public static char high(int uc) {
|
||||
return (char)(0xd800 | (((uc - UCS4_MIN) >> 10) & 0x3ff));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the low UTF-16 surrogate for the given UCS-4 character.
|
||||
*/
|
||||
public static char low(int uc) {
|
||||
return (char)(0xdc00 | ((uc - UCS4_MIN) & 0x3ff));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given surrogate pair into a 32-bit UCS-4 character.
|
||||
*/
|
||||
public static int toUCS4(char c, char d) {
|
||||
return (((c & 0x3ff) << 10) | (d & 0x3ff)) + 0x10000;
|
||||
}
|
||||
|
||||
/**
|
||||
* Surrogate parsing support. Charset implementations may use instances of
|
||||
* this class to handle the details of parsing UTF-16 surrogate pairs.
|
||||
*/
|
||||
public static class Parser {
|
||||
|
||||
public Parser() { }
|
||||
|
||||
private int character; // UCS-4
|
||||
private CoderResult error = CoderResult.UNDERFLOW;
|
||||
private boolean isPair;
|
||||
|
||||
/**
|
||||
* Returns the UCS-4 character previously parsed.
|
||||
*/
|
||||
public int character() {
|
||||
return character;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether or not the previously-parsed UCS-4 character was
|
||||
* originally represented by a surrogate pair.
|
||||
*/
|
||||
public boolean isPair() {
|
||||
return isPair;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of UTF-16 characters consumed by the previous
|
||||
* parse.
|
||||
*/
|
||||
public int increment() {
|
||||
return isPair ? 2 : 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the previous parse operation detected an error, return the object
|
||||
* describing that error.
|
||||
*/
|
||||
public CoderResult error() {
|
||||
return error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an unmappable-input result object, with the appropriate
|
||||
* input length, for the previously-parsed character.
|
||||
*/
|
||||
public CoderResult unmappableResult() {
|
||||
return CoderResult.unmappableForLength(isPair ? 2 : 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a UCS-4 character from the given source buffer, handling
|
||||
* surrogates.
|
||||
*
|
||||
* @param c The first character
|
||||
* @param in The source buffer, from which one more character
|
||||
* will be consumed if c is a high surrogate
|
||||
*
|
||||
* @return Either a parsed UCS-4 character, in which case the isPair()
|
||||
* and increment() methods will return meaningful values, or
|
||||
* -1, in which case error() will return a descriptive result
|
||||
* object
|
||||
*/
|
||||
public int parse(char c, CharBuffer in) {
|
||||
if (isHigh(c)) {
|
||||
if (!in.hasRemaining()) {
|
||||
error = CoderResult.UNDERFLOW;
|
||||
return -1;
|
||||
}
|
||||
char d = in.get();
|
||||
if (isLow(d)) {
|
||||
character = toUCS4(c, d);
|
||||
isPair = true;
|
||||
error = null;
|
||||
return character;
|
||||
}
|
||||
error = CoderResult.malformedForLength(1);
|
||||
return -1;
|
||||
}
|
||||
if (isLow(c)) {
|
||||
error = CoderResult.malformedForLength(1);
|
||||
return -1;
|
||||
}
|
||||
character = c;
|
||||
isPair = false;
|
||||
error = null;
|
||||
return character;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a UCS-4 character from the given source buffer, handling
|
||||
* surrogates.
|
||||
*
|
||||
* @param c The first character
|
||||
* @param ia The input array, from which one more character
|
||||
* will be consumed if c is a high surrogate
|
||||
* @param ip The input index
|
||||
* @param il The input limit
|
||||
*
|
||||
* @return Either a parsed UCS-4 character, in which case the isPair()
|
||||
* and increment() methods will return meaningful values, or
|
||||
* -1, in which case error() will return a descriptive result
|
||||
* object
|
||||
*/
|
||||
public int parse(char c, char[] ia, int ip, int il) {
|
||||
if (isHigh(c)) {
|
||||
if (il - ip < 2) {
|
||||
error = CoderResult.UNDERFLOW;
|
||||
return -1;
|
||||
}
|
||||
char d = ia[ip + 1];
|
||||
if (isLow(d)) {
|
||||
character = toUCS4(c, d);
|
||||
isPair = true;
|
||||
error = null;
|
||||
return character;
|
||||
}
|
||||
error = CoderResult.malformedForLength(1);
|
||||
return -1;
|
||||
}
|
||||
if (isLow(c)) {
|
||||
error = CoderResult.malformedForLength(1);
|
||||
return -1;
|
||||
}
|
||||
character = c;
|
||||
isPair = false;
|
||||
error = null;
|
||||
return character;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Surrogate generation support. Charset implementations may use instances
|
||||
* of this class to handle the details of generating UTF-16 surrogate
|
||||
* pairs.
|
||||
*/
|
||||
public static class Generator {
|
||||
|
||||
public Generator() { }
|
||||
|
||||
private CoderResult error = CoderResult.OVERFLOW;
|
||||
|
||||
/**
|
||||
* If the previous generation operation detected an error, return the
|
||||
* object describing that error.
|
||||
*/
|
||||
public CoderResult error() {
|
||||
return error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates one or two UTF-16 characters to represent the given UCS-4
|
||||
* character.
|
||||
*
|
||||
* @param uc The UCS-4 character
|
||||
* @param len The number of input bytes from which the UCS-4 value
|
||||
* was constructed (used when creating result objects)
|
||||
* @param dst The destination buffer, to which one or two UTF-16
|
||||
* characters will be written
|
||||
*
|
||||
* @return Either a positive count of the number of UTF-16 characters
|
||||
* written to the destination buffer, or -1, in which case
|
||||
* error() will return a descriptive result object
|
||||
*/
|
||||
public int generate(int uc, int len, CharBuffer dst) {
|
||||
if (uc <= 0xffff) {
|
||||
if (is(uc)) {
|
||||
error = CoderResult.malformedForLength(len);
|
||||
return -1;
|
||||
}
|
||||
if (dst.remaining() < 1) {
|
||||
error = CoderResult.OVERFLOW;
|
||||
return -1;
|
||||
}
|
||||
dst.put((char)uc);
|
||||
error = null;
|
||||
return 1;
|
||||
}
|
||||
if (uc < UCS4_MIN) {
|
||||
error = CoderResult.malformedForLength(len);
|
||||
return -1;
|
||||
}
|
||||
if (uc <= UCS4_MAX) {
|
||||
if (dst.remaining() < 2) {
|
||||
error = CoderResult.OVERFLOW;
|
||||
return -1;
|
||||
}
|
||||
dst.put(high(uc));
|
||||
dst.put(low(uc));
|
||||
error = null;
|
||||
return 2;
|
||||
}
|
||||
error = CoderResult.unmappableForLength(len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates one or two UTF-16 characters to represent the given UCS-4
|
||||
* character.
|
||||
*
|
||||
* @param uc The UCS-4 character
|
||||
* @param len The number of input bytes from which the UCS-4 value
|
||||
* was constructed (used when creating result objects)
|
||||
* @param da The destination array, to which one or two UTF-16
|
||||
* characters will be written
|
||||
* @param dp The destination position
|
||||
* @param dl The destination limit
|
||||
*
|
||||
* @return Either a positive count of the number of UTF-16 characters
|
||||
* written to the destination buffer, or -1, in which case
|
||||
* error() will return a descriptive result object
|
||||
*/
|
||||
public int generate(int uc, int len, char[] da, int dp, int dl) {
|
||||
if (uc <= 0xffff) {
|
||||
if (is(uc)) {
|
||||
error = CoderResult.malformedForLength(len);
|
||||
return -1;
|
||||
}
|
||||
if (dl - dp < 1) {
|
||||
error = CoderResult.OVERFLOW;
|
||||
return -1;
|
||||
}
|
||||
da[dp] = (char)uc;
|
||||
error = null;
|
||||
return 1;
|
||||
}
|
||||
if (uc < UCS4_MIN) {
|
||||
error = CoderResult.malformedForLength(len);
|
||||
return -1;
|
||||
}
|
||||
if (uc <= UCS4_MAX) {
|
||||
if (dl - dp < 2) {
|
||||
error = CoderResult.OVERFLOW;
|
||||
return -1;
|
||||
}
|
||||
da[dp] = high(uc);
|
||||
da[dp + 1] = low(uc);
|
||||
error = null;
|
||||
return 2;
|
||||
}
|
||||
error = CoderResult.unmappableForLength(len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.codemodel.internal.util;
|
||||
|
||||
import java.io.FilterWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
|
||||
/**
|
||||
* {@link Writer} that escapes non US-ASCII characters into
|
||||
* Java Unicode escape \\uXXXX.
|
||||
*
|
||||
* This process is necessary if the method names or field names
|
||||
* contain non US-ASCII characters.
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
public class UnicodeEscapeWriter extends FilterWriter {
|
||||
|
||||
public UnicodeEscapeWriter( Writer next ) {
|
||||
super(next);
|
||||
}
|
||||
|
||||
public final void write(int ch) throws IOException {
|
||||
if(!requireEscaping(ch)) out.write(ch);
|
||||
else {
|
||||
// need to escape
|
||||
out.write("\\u");
|
||||
String s = Integer.toHexString(ch);
|
||||
for( int i=s.length(); i<4; i++ )
|
||||
out.write('0');
|
||||
out.write(s);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Can be overrided. Return true if the character
|
||||
* needs to be escaped.
|
||||
*/
|
||||
protected boolean requireEscaping(int ch) {
|
||||
if(ch>=128) return true;
|
||||
|
||||
// control characters
|
||||
if( ch<0x20 && " \t\r\n".indexOf(ch)==-1 ) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public final void write(char[] buf, int off, int len) throws IOException {
|
||||
for( int i=0; i<len; i++ )
|
||||
write(buf[off+i]);
|
||||
}
|
||||
|
||||
public final void write(char[] buf) throws IOException {
|
||||
write(buf,0,buf.length);
|
||||
}
|
||||
|
||||
public final void write(String buf, int off, int len) throws IOException {
|
||||
write( buf.toCharArray(), off, len );
|
||||
}
|
||||
|
||||
public final void write(String buf) throws IOException {
|
||||
write( buf.toCharArray(), 0, buf.length() );
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user