@@ -25,9 +25,22 @@ public final class AnsiParser {
2525 // implies FLAG_PARSE_DISABLE_SUBSCRIPT
2626 public static final int FLAG_PARSE_DISABLE_ATTRIBUTES = 0x0002 ;
2727 // Disable extra color customization other than foreground or background
28+ // Useful to have consistent display across Android versions
2829 public static final int FLAG_PARSE_DISABLE_EXTRAS_COLORS = 0x0004 ;
2930 // Disable subscript and superscript text
3031 public static final int FLAG_PARSE_DISABLE_SUBSCRIPT = 0x0008 ;
32+ // Disable all attributes changes
33+ public static final int FLAGS_DISABLE_ALL =
34+ FLAG_PARSE_DISABLE_COLORS | FLAG_PARSE_DISABLE_ATTRIBUTES ;
35+
36+ /**
37+ * Replace escape sequence using a control character by a normal escape sequence
38+ * This allow to use {@link String#trim()} without the risk for the escape sequence
39+ * to be elso trimmed
40+ */
41+ public static String patchEscapeSequence (String string ) {
42+ return string .replace (ESCAPE2 , ESCAPE1 );
43+ }
3144
3245 public static Spannable parseAsSpannable (@ NonNull String text ) {
3346 return parseAsSpannable (text , null );
@@ -274,5 +287,9 @@ public static void setAnsiText(@NonNull TextView text,@NonNull String ansiText,
274287 text .setText (parseAsSpannable (ansiText , parseFlags ));
275288 }
276289
290+ public static String trimEscapeSequences (String string ) {
291+ return parseAsSpannable (string , FLAGS_DISABLE_ALL ).toString ();
292+ }
293+
277294 private AnsiParser () {}
278295}
0 commit comments