package com.lagunex.util;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 *
 * @author Carlos A. Henríquez Q. <carlos.henriquez@lagunex.com>
 */
public class StringUtils {
    public static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    public static final String SEPARATOR = "|";
    
    public static String collapseLines(String message) {
        return message.replaceAll("\n", "\\\\n");
    }

    public static String uncollapseLines(String message) {
        return message.replaceAll("\\\\n", "\n");
    }
    
    public static String escape(String message) {
        return escape(message, SEPARATOR);
    }
    
    public static String escape(String message, String reserved) {
        String escaped = String.format("\\%s", reserved);
        return message.replace(reserved, escaped).replaceFirst("\\\\$", "\\\\ ");
    }

    public static String unescape(String escapedMessage) {
        return unescape(escapedMessage, SEPARATOR);
    }
    
    public static String unescape(String escapedMessage, String reserved) {
        String escaped = String.format("\\%s", reserved);
        return escapedMessage.replace(escaped, reserved).replaceFirst("\\\\ $", "\\\\"); 
    }

    public static String formatDateTime(LocalDateTime dateTime) {
        return dateTime.format(DATE_TIME_FORMATTER);
    }
}

@@ -102,16 +102,59 @@
 %0A%0A/**%0A *
+ Utility class that manipulates Strings%0A * 
 %0A * @aut
@@ -419,677 +419,1527 @@
     
-public static String collapseLines(String message) %7B%0A        return message.replaceAll(%22%5Cn%22, %22%5C%5C%5C%5Cn%22);%0A    %7D%0A%0A    public static String uncollapseLines(String message) %7B%0A        return message.replaceAll(%22%5C%5C%5C%5Cn%22, %22%5Cn%22);%0A    %7D%0A    %0A    public static String escape(String message) %7B%0A        return escape(message, SEPARATOR);%0A    %7D%0A    %0A    public static String escape(String message, String reserved) %7B%0A        String escaped = String.format(%22%5C%5C%25s%22, reserved);%0A        return message.replace(reserved, escaped).replaceFirst(%22%5C%5C%5C%5C$%22, %22%5C%5C%5C%5C %22);%0A    %7D%0A%0A    public static String unescape(String escapedMessage) %7B%0A        return unescape(escapedMessage, SEPARATOR);%0A    %7D%0A    
+/**%0A     * Returns a string with all break lines replaced by the string %22%5Cn%22%0A     * @param message%0A     * @return %0A     */%0A    public static String collapseLines(String message) %7B%0A        return message.replaceAll(%22%5Cn%22, %22%5C%5C%5C%5Cn%22);%0A    %7D%0A%0A    /**%0A     * Replaces all occurrence of the string %22%5Cn%22 with a break line and returns the result%0A     * @param message%0A     * @return %0A     */%0A    public static String uncollapseLines(String message) %7B%0A        return message.replaceAll(%22%5C%5C%5C%5Cn%22, %22%5Cn%22);%0A    %7D%0A    %0A    /**%0A     * Returns a string with all occurrence of StringUtils.SEPARATOR escaped%0A     * @param message%0A     * @return %0A     */%0A    public static String escape(String message) %7B%0A        return escape(message, SEPARATOR);%0A    %7D%0A    %0A    /**%0A     * Returns a string with all occurrence of reserved escaped%0A     * @param message%0A     * @param reserved%0A     * @return %0A     */%0A    public static String escape(String message, String reserved) %7B%0A        String escaped = String.format(%22%5C%5C%25s%22, reserved);%0A        return message.replace(reserved, escaped).replaceFirst(%22%5C%5C%5C%5C$%22, %22%5C%5C%5C%5C %22);%0A    %7D%0A%0A    /**%0A     * Returns a string with all escaped occurrence of StringUtils.SEPARATOR unescaped%0A     * @param escapedMessage%0A     * @return %0A     */%0A    public static String unescape(String escapedMessage) %7B%0A        return unescape(escapedMessage, SEPARATOR);%0A    %7D%0A    %0A    /**%0A     * Returns a string with all escaped occurrence of reserved unescaped%0A     * @param escapedMessage%0A     * @param reserved%0A     * @return %0A     */
 %0A   
@@ -2162,24 +2162,150 @@
 %22); %0A    %7D%0A%0A
+    /**%0A     * Returns a string representing dateTime with DATE_TIME_FORMATTER%0A     * @param dateTime%0A     * @return %0A     */%0A
     public s

add comments