aboutsummaryrefslogtreecommitdiff
path: root/tests/BugTok.java
blob: c5bc445cf76df810ad9bee726a0c624f8a5d2d26 (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
import java.util.Vector ;
class BugTok {

	public static String[] decoupe(String s,String sep) {
		int index=0, last=0, length=s.length();
		Vector v = new Vector();
		if (length!=0) while (true) {
		  index=s.indexOf(sep,last);
		  if (index==-1) {
		    v.add(s.substring(last,length));
		    break;
		  } else if (index<s.length()) {
		    v.add(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  changé ma chanson"," ")) ;
	  doprint(decoupe(" ils ont  changé ma chanson"," ")) ;
	  doprint(decoupe("\u0003ils\u0003ont\u0003\u0003changé ma chanson","\u0003")) ;
	  doprint(decoupe(""," ")) ;
	}
}