Mercurial > 510Connectbot
comparison src/com/trilead/ssh2/util/Tokenizer.java @ 0:0ce5cc452d02
initial version
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Thu, 22 May 2014 10:41:19 -0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:0ce5cc452d02 |
---|---|
1 | |
2 package com.trilead.ssh2.util; | |
3 | |
4 /** | |
5 * Tokenizer. Why? Because StringTokenizer is not available in J2ME. | |
6 * | |
7 * @author Christian Plattner, plattner@trilead.com | |
8 * @version $Id: Tokenizer.java,v 1.1 2007/10/15 12:49:57 cplattne Exp $ | |
9 */ | |
10 public class Tokenizer { | |
11 /** | |
12 * Exists because StringTokenizer is not available in J2ME. | |
13 * Returns an array with at least 1 entry. | |
14 * | |
15 * @param source must be non-null | |
16 * @param delimiter | |
17 * @return an array of Strings | |
18 */ | |
19 public static String[] parseTokens(String source, char delimiter) { | |
20 int numtoken = 1; | |
21 | |
22 for (int i = 0; i < source.length(); i++) { | |
23 if (source.charAt(i) == delimiter) | |
24 numtoken++; | |
25 } | |
26 | |
27 String list[] = new String[numtoken]; | |
28 int nextfield = 0; | |
29 | |
30 for (int i = 0; i < numtoken; i++) { | |
31 if (nextfield >= source.length()) { | |
32 list[i] = ""; | |
33 } | |
34 else { | |
35 int idx = source.indexOf(delimiter, nextfield); | |
36 | |
37 if (idx == -1) | |
38 idx = source.length(); | |
39 | |
40 list[i] = source.substring(nextfield, idx); | |
41 nextfield = idx + 1; | |
42 } | |
43 } | |
44 | |
45 return list; | |
46 } | |
47 } |