src/jdk.internal.le/share/classes/jdk/internal/jline/internal/Ansi.java
changeset 53333 fd6de53a0d6e
parent 53332 ab474ef0a0ac
parent 53010 086dfcfc3731
child 53334 b94283cb226b
equal deleted inserted replaced
53332:ab474ef0a0ac 53333:fd6de53a0d6e
     1 /*
       
     2  * Copyright (c) 2002-2016, the original author or authors.
       
     3  *
       
     4  * This software is distributable under the BSD license. See the terms of the
       
     5  * BSD license in the documentation provided with this software.
       
     6  *
       
     7  * http://www.opensource.org/licenses/bsd-license.php
       
     8  */
       
     9 package jdk.internal.jline.internal;
       
    10 
       
    11 import java.util.regex.Pattern;
       
    12 
       
    13 /**
       
    14  * Ansi support.
       
    15  *
       
    16  * @author <a href="mailto:gnodet@gmail.com">Guillaume Nodet</a>
       
    17  * @since 2.13
       
    18  */
       
    19 public class Ansi {
       
    20 
       
    21     public static String stripAnsi(String str) {
       
    22         if (str == null) return "";
       
    23         return ANSI_CODE_PATTERN.matcher(str).replaceAll("");
       
    24         //was:
       
    25 //        try {
       
    26 //            ByteArrayOutputStream baos = new ByteArrayOutputStream();
       
    27 //            AnsiOutputStream aos = new AnsiOutputStream(baos);
       
    28 //            aos.write(str.getBytes());
       
    29 //            aos.close();
       
    30 //            return baos.toString();
       
    31 //        } catch (IOException e) {
       
    32 //            return str;
       
    33 //        }
       
    34     }
       
    35 
       
    36     public static final Pattern ANSI_CODE_PATTERN = Pattern.compile("\033\\[[\060-\077]*[\040-\057]*[\100-\176]");
       
    37 
       
    38 }