You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by us...@apache.org on 2013/10/16 13:49:50 UTC
svn commit: r1532737 - in
/lucene/dev/branches/lucene4956/lucene/analysis/arirang/src/java/org/apache/lucene/analysis/ko/utils:
StrBuilder.java StringEscapeUtil.java UnhandledException.java
Author: uschindler
Date: Wed Oct 16 11:49:49 2013
New Revision: 1532737
URL: http://svn.apache.org/r1532737
Log:
LUCENE-4956: Remove stuff not really needed. TODO: add attribution, because this code is borrowed, too!
Removed:
lucene/dev/branches/lucene4956/lucene/analysis/arirang/src/java/org/apache/lucene/analysis/ko/utils/StrBuilder.java
lucene/dev/branches/lucene4956/lucene/analysis/arirang/src/java/org/apache/lucene/analysis/ko/utils/UnhandledException.java
Modified:
lucene/dev/branches/lucene4956/lucene/analysis/arirang/src/java/org/apache/lucene/analysis/ko/utils/StringEscapeUtil.java
Modified: lucene/dev/branches/lucene4956/lucene/analysis/arirang/src/java/org/apache/lucene/analysis/ko/utils/StringEscapeUtil.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4956/lucene/analysis/arirang/src/java/org/apache/lucene/analysis/ko/utils/StringEscapeUtil.java?rev=1532737&r1=1532736&r2=1532737&view=diff
==============================================================================
--- lucene/dev/branches/lucene4956/lucene/analysis/arirang/src/java/org/apache/lucene/analysis/ko/utils/StringEscapeUtil.java (original)
+++ lucene/dev/branches/lucene4956/lucene/analysis/arirang/src/java/org/apache/lucene/analysis/ko/utils/StringEscapeUtil.java Wed Oct 16 11:49:49 2013
@@ -17,59 +17,27 @@ package org.apache.lucene.analysis.ko.ut
* limitations under the License.
*/
-import java.io.IOException;
-import java.io.StringWriter;
-import java.io.Writer;
-
-public class StringEscapeUtil {
+// nocommit: parts of this class seems to borrowed from commons-lang, add correct attribution!
+class StringEscapeUtil {
+
/**
- * <p>Unescapes any Java literals found in the <code>String</code>.
- * For example, it will turn a sequence of <code>'\'</code> and
- * <code>'n'</code> into a newline character, unless the <code>'\'</code>
- * is preceded by another <code>'\'</code>.</p>
+ * <p>
+ * Unescapes any Java literals found in the <code>String</code>. For example,
+ * it will turn a sequence of <code>'\'</code> and <code>'n'</code> into a
+ * newline character, unless the <code>'\'</code> is preceded by another
+ * <code>'\'</code>.
+ * </p>
*
- * @param str the <code>String</code> to unescape, may be null
- * @return a new unescaped <code>String</code>, <code>null</code> if null string input
+ * @param str
+ * the <code>String</code> to unescape, may be null
+ * @return a new unescaped <code>String</code>, <code>null</code> if null
+ * string input
*/
public static String unescapeJava(String str) {
- if (str == null) {
- return null;
- }
- try {
- StringWriter writer = new StringWriter(str.length());
- unescapeJava(writer, str);
- return writer.toString();
- } catch (IOException ioe) {
- // this should never ever happen while writing to a StringWriter
- throw new UnhandledException(ioe);
- }
- }
-
- /**
- * <p>Unescapes any Java literals found in the <code>String</code> to a
- * <code>Writer</code>.</p>
- *
- * <p>For example, it will turn a sequence of <code>'\'</code> and
- * <code>'n'</code> into a newline character, unless the <code>'\'</code>
- * is preceded by another <code>'\'</code>.</p>
- *
- * <p>A <code>null</code> string input has no effect.</p>
- *
- * @param out the <code>Writer</code> used to output unescaped characters
- * @param str the <code>String</code> to unescape, may be null
- * @throws IllegalArgumentException if the Writer is <code>null</code>
- * @throws IOException if error occurs on underlying Writer
- */
- public static void unescapeJava(Writer out, String str) throws IOException {
- if (out == null) {
- throw new IllegalArgumentException("The Writer must not be null");
- }
- if (str == null) {
- return;
- }
+ StringBuilder out = new StringBuilder(str.length());
int sz = str.length();
- StrBuilder unicode = new StrBuilder(4);
+ StringBuilder unicode = new StringBuilder(4);
boolean hadSlash = false;
boolean inUnicode = false;
for (int i = 0; i < sz; i++) {
@@ -81,15 +49,11 @@ public class StringEscapeUtil {
if (unicode.length() == 4) {
// unicode now contains the four hex digits
// which represents our unicode character
- try {
- int value = Integer.parseInt(unicode.toString(), 16);
- out.write((char) value);
- unicode.setLength(0);
- inUnicode = false;
- hadSlash = false;
- } catch (NumberFormatException nfe) {
- throw new UnhandledException("Unable to parse unicode value: " + unicode, nfe);
- }
+ int value = Integer.parseInt(unicode.toString(), 16);
+ out.append((char) value);
+ unicode.setLength(0);
+ inUnicode = false;
+ hadSlash = false;
}
continue;
}
@@ -98,36 +62,36 @@ public class StringEscapeUtil {
hadSlash = false;
switch (ch) {
case '\\':
- out.write('\\');
+ out.append('\\');
break;
case '\'':
- out.write('\'');
+ out.append('\'');
break;
case '\"':
- out.write('"');
+ out.append('"');
break;
case 'r':
- out.write('\r');
+ out.append('\r');
break;
case 'f':
- out.write('\f');
+ out.append('\f');
break;
case 't':
- out.write('\t');
+ out.append('\t');
break;
case 'n':
- out.write('\n');
+ out.append('\n');
break;
case 'b':
- out.write('\b');
+ out.append('\b');
break;
case 'u': {
// uh-oh, we're in unicode country....
inUnicode = true;
break;
}
- default :
- out.write(ch);
+ default:
+ out.append(ch);
break;
}
continue;
@@ -135,12 +99,14 @@ public class StringEscapeUtil {
hadSlash = true;
continue;
}
- out.write(ch);
+ out.append(ch);
}
if (hadSlash) {
// then we're in the weird case of a \ at the end of the
// string, let's output it anyway.
- out.write('\\');
+ out.append('\\');
}
+ return out.toString();
}
+
}