Removing unnecessary Escape*AsciiAsUnicode classes. UnicodeEscaper now handles the range concept directly and the ctrl character lookup table is now a direct LookupTranslator defined in EscapeUtils. cf LANG-505
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@788259 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
bda5d16000
commit
171fa698d3
|
@ -1,69 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.commons.lang.text.translate;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
|
||||
/**
|
||||
* Escapes ASCII under 32 to Unicode, except for the following
|
||||
* special values, '\b \n \t \f \r', which are escaped to their
|
||||
* Java types.
|
||||
* @since 3.0
|
||||
*/
|
||||
// TODO: Is this not the combination of a LookupTranslator for the 5
|
||||
// TODO: special values, followed by a UnicodeEscaper?
|
||||
// TODO: It means passing a numerical range to the UnicodeEscaper
|
||||
// TOOD: to make it only hit < 32.
|
||||
public class EscapeLowAsciiAsUnicode extends UnicodeEscaper {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public boolean translate(int ch, Writer out) throws IOException {
|
||||
if (ch < 32) {
|
||||
switch (ch) {
|
||||
case '\b' :
|
||||
out.write('\\');
|
||||
out.write('b');
|
||||
break;
|
||||
case '\n' :
|
||||
out.write('\\');
|
||||
out.write('n');
|
||||
break;
|
||||
case '\t' :
|
||||
out.write('\\');
|
||||
out.write('t');
|
||||
break;
|
||||
case '\f' :
|
||||
out.write('\\');
|
||||
out.write('f');
|
||||
break;
|
||||
case '\r' :
|
||||
out.write('\\');
|
||||
out.write('r');
|
||||
break;
|
||||
default :
|
||||
super.translate(ch, out);
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.commons.lang.text.translate;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
|
||||
/**
|
||||
* Translates codepoints greater than ASCII 127 to the unicode.
|
||||
* @since 3.0
|
||||
*/
|
||||
public class EscapeNonAsciiAsUnicode extends UnicodeEscaper {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public boolean translate(int codepoint, Writer out) throws IOException {
|
||||
// if (codepoint > 0xffff) {
|
||||
// TODO: Figure out what to do. Output as two unicodes?
|
||||
// Does this make this a Java-specific output class?
|
||||
|
||||
if (codepoint > 0x7f) {
|
||||
super.translate(codepoint, out);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -59,8 +59,15 @@ public class EscapeUtils {
|
|||
{"\\", "\\\\"},
|
||||
{"/", "\\/"}
|
||||
}),
|
||||
new EscapeLowAsciiAsUnicode(),
|
||||
new EscapeNonAsciiAsUnicode()
|
||||
new LookupTranslator(
|
||||
new String[][] {
|
||||
{"\b", "\\b"},
|
||||
{"\n", "\\n"},
|
||||
{"\t", "\\t"},
|
||||
{"\f", "\\f"},
|
||||
{"\r", "\\r"}
|
||||
}),
|
||||
UnicodeEscaper.outsideOf(32, 0x7f)
|
||||
);
|
||||
|
||||
public static final String escapeEcmaScript(String input) {
|
||||
|
|
Loading…
Reference in New Issue