aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/ch/ethz/ssh2/util/Tokenizer.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/ch/ethz/ssh2/util/Tokenizer.java')
-rw-r--r--src/main/java/ch/ethz/ssh2/util/Tokenizer.java54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/main/java/ch/ethz/ssh2/util/Tokenizer.java b/src/main/java/ch/ethz/ssh2/util/Tokenizer.java
new file mode 100644
index 0000000..6665254
--- /dev/null
+++ b/src/main/java/ch/ethz/ssh2/util/Tokenizer.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
+ * Please refer to the LICENSE.txt for licensing details.
+ */
+package ch.ethz.ssh2.util;
+
+/**
+ * Tokenizer. Why? Because StringTokenizer is not available in J2ME.
+ *
+ * @author Christian Plattner
+ * @version 2.50, 03/15/10
+ */
+public class Tokenizer
+{
+ /**
+ * Exists because StringTokenizer is not available in J2ME.
+ * Returns an array with at least 1 entry.
+ *
+ * @param source must be non-null
+ * @param delimiter
+ * @return an array of Strings
+ */
+ public static String[] parseTokens(String source, char delimiter)
+ {
+ int numtoken = 1;
+
+ for (int i = 0; i < source.length(); i++)
+ {
+ if (source.charAt(i) == delimiter)
+ numtoken++;
+ }
+
+ String list[] = new String[numtoken];
+ int nextfield = 0;
+
+ for (int i = 0; i < numtoken; i++)
+ {
+ if (nextfield >= source.length())
+ {
+ list[i] = "";
+ }
+ else
+ {
+ int idx = source.indexOf(delimiter, nextfield);
+ if (idx == -1)
+ idx = source.length();
+ list[i] = source.substring(nextfield, idx);
+ nextfield = idx + 1;
+ }
+ }
+
+ return list;
+ }
+}