[Mulgara-svn] r1550 - trunk/src/jar/querylang/java/org/mulgara/protocol/http

pag at mulgara.org pag at mulgara.org
Wed Feb 25 18:59:01 UTC 2009


Author: pag
Date: 2009-02-25 10:59:00 -0800 (Wed, 25 Feb 2009)
New Revision: 1550

Modified:
   trunk/src/jar/querylang/java/org/mulgara/protocol/http/LocalTriple.java
Log:
Refactored unescaping of strings into the org.mulgara.util package

Modified: trunk/src/jar/querylang/java/org/mulgara/protocol/http/LocalTriple.java
===================================================================
--- trunk/src/jar/querylang/java/org/mulgara/protocol/http/LocalTriple.java	2009-02-25 18:57:22 UTC (rev 1549)
+++ trunk/src/jar/querylang/java/org/mulgara/protocol/http/LocalTriple.java	2009-02-25 18:59:00 UTC (rev 1550)
@@ -15,8 +15,6 @@
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
 import java.util.Set;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -29,6 +27,7 @@
 import org.mulgara.query.rdf.BlankNodeImpl;
 import org.mulgara.query.rdf.LiteralImpl;
 import org.mulgara.query.rdf.URIReferenceImpl;
+import org.mulgara.util.StringUtil;
 
 /**
  * Represents a triple to be created or removed. Null values indicate blank nodes.
@@ -203,7 +202,7 @@
           }
         }
       }
-      return unescape(m.group(1));
+      return StringUtil.unescapeJavaString(m.group(1));
     }
 
 
@@ -223,41 +222,4 @@
     }
   }
 
-
-  /** Map of escape characters to their character codes */
-  private static Map<Character,String> map = new HashMap<Character,String>();
-  static {
-    map.put('t', "\t");
-    map.put('t', "\t");
-    map.put('b', "\b");
-    map.put('n', "\n");
-    map.put('r', "\r");
-    map.put('f', "\f");
-    map.put('\\', "\\");
-    map.put('"', "\"");
-    map.put('\'', "'");
-  }
-
-
-  /**
-   * Search for escape characters in a string, and replace them with the request values.
-   * @param s The string to search.
-   * @return A new string with all escape characters replaced with the originals.
-   */
-  static final String unescape(String s) {
-    StringBuilder sb = new StringBuilder();
-    int last = 0;
-    int pos = 0;
-    while ((pos = s.indexOf('\\', pos)) >= 0) {
-      sb.append(s.substring(last, pos));
-      if (++pos == s.length()) break;
-      char c = s.charAt(pos);
-      String m = map.get(c);
-      if (m != null) sb.append(m);
-      else sb.append(c);
-      last = ++pos;
-    }
-    sb.append(s.substring(last));
-    return sb.toString();
-  }
 }




More information about the Mulgara-svn mailing list