src/Tools/Setup/isabelle/setup/Library.java
changeset 73963 59b6f0462086
child 73984 c606a8ff5ccc
equal deleted inserted replaced
73962:5351719ab2a0 73963:59b6f0462086
       
     1 /*  Title:      Tools/Setup/isabelle/setup/Library.java
       
     2     Author:     Makarius
       
     3 
       
     4 Basic library.
       
     5 */
       
     6 
       
     7 package isabelle.setup;
       
     8 
       
     9 
       
    10 import java.util.Arrays;
       
    11 import java.util.LinkedList;
       
    12 import java.util.List;
       
    13 
       
    14 
       
    15 public class Library
       
    16 {
       
    17     public static String cat_lines(Iterable<? extends CharSequence> lines)
       
    18     {
       
    19         return String.join("\n", lines);
       
    20     }
       
    21 
       
    22     public static List<String> split_lines(String str)
       
    23     {
       
    24         if (str.isEmpty()) { return List.of(); }
       
    25         else {
       
    26             List<String> result = new LinkedList<String>();
       
    27             result.addAll(Arrays.asList(str.split("\\n")));
       
    28             return List.copyOf(result);
       
    29         }
       
    30     }
       
    31 
       
    32     public static String prefix_lines(String prfx, String str)
       
    33     {
       
    34         if (str.isEmpty()) { return str; }
       
    35         else {
       
    36             StringBuilder result = new StringBuilder();
       
    37             for (String s : split_lines(str)) {
       
    38                 result.append(prfx);
       
    39                 result.append(s);
       
    40             }
       
    41             return result.toString();
       
    42         }
       
    43     }
       
    44 
       
    45     public static String trim_line(String s)
       
    46     {
       
    47         if (s.endsWith("\r\n")) { return s.substring(0, s.length() - 2); }
       
    48         else if (s.endsWith("\r") || s.endsWith("\n")) { return s.substring(0, s.length() - 1); }
       
    49         else { return s; }
       
    50     }
       
    51 }