1
15
16 package gate.util;
17
18 import java.io.*;
19
20
21 public class Strings {
22
23
24 private static final boolean DEBUG = false;
25
26
27 private static char padChar = ' ';
28
29
30 private static String newline = System.getProperty("line.separator");
31
32
33 public static String getNl() { return newline; }
34
35
36 private static String pathSep = System.getProperty("path.separator");
37
38
39 public static String getPathSep() { return pathSep; }
40
41
42 private static String fileSep = System.getProperty("file.separator");
43
44
45 public static String getFileSep() { return fileSep; }
46
47
48 public static String addPadding(String pad, int n) {
49 StringBuffer s = new StringBuffer(pad);
50 for(int i = 0; i < n; i++)
51 s.append(padChar);
52
53 return s.toString();
54 }
56
57 public static String addLineNumbers(String text) {
58 BufferedReader reader = new BufferedReader(new StringReader(text));
60 String line = null;
61 StringBuffer result = new StringBuffer();
62
63 try {
64 for(int lineNum = 1; ( line = reader.readLine() ) != null; lineNum++) {
65 String pad;
66 if(lineNum < 10) pad = " ";
67 else pad = "";
68 result.append(pad + lineNum + " " + line + Strings.getNl());
69 }
70 } catch(IOException ie) { }
71
72 return result.toString();
73 }
75 }