package org.zwobble.mammoth.internal.styles.parsing;

import java.nio.CharBuffer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class EscapeSequences {
    private static final Pattern PATTERN = Pattern.compile("\\\\(.)");

    public static String decode(String value) {
        return decode(CharBuffer.wrap(value));
    }

    private static String decode(CharBuffer value) {
        Matcher matcher = PATTERN.matcher(value);
        StringBuilder decoded = new StringBuilder();
        int lastIndex = 0;
        while (matcher.find()) {
            decoded.append(value.subSequence(lastIndex, matcher.start()));
            decoded.append(escapeSequence(matcher.group(1)));
            lastIndex = matcher.end();
        }
        decoded.append(value.subSequence(lastIndex, value.length()));
        return decoded.toString();
    }

    private static char escapeSequence(String code) {
        switch (code) {
            case "n":
                return '\n';
            case "r":
                return '\r';
            case "t":
                return '\t';
            default:
                return code.charAt(0);
        }
    }
}

@@ -51,36 +51,8 @@
 g;%0A%0A
-import java.nio.CharBuffer;%0A
 impo
@@ -79,16 +79,16 @@
 atcher;%0A
+
 import j
@@ -267,115 +267,8 @@
 ) %7B%0A
-        return decode(CharBuffer.wrap(value));%0A    %7D%0A%0A    private static String decode(CharBuffer value) %7B%0A
     
@@ -458,32 +458,30 @@
 nd(value.sub
-Sequence
+string
 (lastIndex, 
@@ -642,24 +642,22 @@
 alue.sub
-Sequence
+string
 (lastInd

Decode escape sequences in string without CharBuffer