aboutsummaryrefslogtreecommitdiff
path: root/tests/BugTok.java
blob: 0bfca0d1322045f81781def2eb97fcafc0245cc3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
 * BugTok.
 *
 * @author Yannick Jestin <mailto:jestin@cena.fr>
 *
 * (c) CENA
 *
 * 1.2.3:
 *   - replace Vector.add by Vector.addElement() to maintain jdk1.1
 *   compatibility
 */
import java.util.Vector ;
class BugTok {

	public static String[] decoupe(String s,String sep) {
		int index=0, last=0, length=s.length();
		Vector<String> v = new Vector<String>();
		if (length!=0) while (true) {
		  index=s.indexOf(sep,last);
		  if (index==-1) {
		    v.addElement(s.substring(last,length));
		    break;
		  } else if (index<s.length()) {
		    v.addElement(s.substring(last,index));
		    last=index+1;
		  } else {
		    break;
		  }
		}
		String[] tab = new String[v.size()];
		v.copyInto(tab);
		return tab;
	}

	public static void doprint(String[] tab) {
	  System.out.println("------------ "+tab.length+" elements --------------");
	  for (int i=0; i<tab.length;i++) {
	    System.out.println("'"+tab[i]+"'");
	  }
	  System.out.println("------------------------------------------------------");
	}

	public static void main(String[] arg) {
	  doprint(decoupe("ils ont  change ma chanson"," ")) ;
	  doprint(decoupe(" ils ont  change ma chanson"," ")) ;
	  doprint(decoupe("\u0003ils\u0003ont\u0003\u0003change ma chanson","\u0003")) ;
	  doprint(decoupe(""," ")) ;
	}
}