logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1405003 - /logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/AnsiEscape.java
Date Fri, 02 Nov 2012 15:20:18 GMT
Author: ggregory
Date: Fri Nov  2 15:20:18 2012
New Revision: 1405003

URL: http://svn.apache.org/viewvc?rev=1405003&view=rev
Log:
Refactor whitespace regexs.

Modified:
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/AnsiEscape.java

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/AnsiEscape.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/AnsiEscape.java?rev=1405003&r1=1405002&r2=1405003&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/AnsiEscape.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/AnsiEscape.java
Fri Nov  2 15:20:18 2012
@@ -79,6 +79,8 @@ public enum AnsiEscape {
     BG_CYAN("46"),
     BG_WHITE("47");
 
+    private static final String WHITESPACE_REGEX = "\\s*";
+    
     private final String code;
 
     private AnsiEscape(String code) {
@@ -89,6 +91,10 @@ public enum AnsiEscape {
         return PREFIX.getCode() + SUFFIX.getCode();
     }
 
+    private static String toRegexSeparator(String separator) {
+        return WHITESPACE_REGEX + separator + WHITESPACE_REGEX;
+    }
+
     public String getCode() {
         return code;
     }
@@ -116,7 +122,7 @@ public enum AnsiEscape {
      * @return a new map
      */
     public static Map<String, String> createMap(String values, String[] dontEscapeKeys)
{
-        return createMap(values.split("\\s*,\\s*"), dontEscapeKeys);
+        return createMap(values.split(toRegexSeparator(",")), dontEscapeKeys);
     }
 
     /**
@@ -146,7 +152,7 @@ public enum AnsiEscape {
         Arrays.sort(sortedIgnoreKeys);
         Map<String, String> map = new HashMap<String, String>();
         for (String string : values) {
-            String[] keyValue = string.split("\\s*=\\s*");
+            String[] keyValue = string.split(toRegexSeparator("="));
             if (keyValue.length > 1) {
                 final String key = keyValue[0].toUpperCase(Locale.ENGLISH);
                 final String value = keyValue[1];



Mime
View raw message