1 package net.sf.logdistiller.util;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 import java.text.ParseException;
18
19 public class StringCutter
20 {
21 private final String src;
22
23 private int index = 0;
24
25 public StringCutter( String src )
26 {
27 this.src = src;
28 }
29
30 public StringCutter( String src, int startIndex )
31 {
32 this.src = src;
33 this.index = startIndex;
34 }
35
36 public String parseTo( String delimiter )
37 throws ParseException
38 {
39 return parseTo( delimiter, true );
40 }
41
42 public String parseTo( String delimiter, boolean failIfNotFound )
43 throws ParseException
44 {
45 int to = src.indexOf( delimiter, index );
46 if ( to < index )
47 {
48 if ( failIfNotFound )
49 {
50 throw new ParseException( "delimiter '" + delimiter + "' not found starting from index " + index
51 + " in '" + src + "'", index );
52 }
53 String token = src.substring( index );
54 index = src.length();
55 return token;
56 }
57 String token = src.substring( index, to );
58 index = to + delimiter.length();
59 return token;
60 }
61
62 public String getRemaining()
63 {
64 return src.substring( index );
65 }
66 }