From 25dadc85140b1f688a4cf0c2de8b961a07b10f11 Mon Sep 17 00:00:00 2001 From: Peter Mount Date: Mon, 17 Apr 2000 20:07:56 +0000 Subject: Another attempt at 7.0 --- .../jdbc/org/postgresql/util/PGtokenizer.java | 197 +++++++++++++++++++++ 1 file changed, 197 insertions(+) create mode 100644 src/interfaces/jdbc/org/postgresql/util/PGtokenizer.java (limited to 'src/interfaces/jdbc/org/postgresql/util/PGtokenizer.java') diff --git a/src/interfaces/jdbc/org/postgresql/util/PGtokenizer.java b/src/interfaces/jdbc/org/postgresql/util/PGtokenizer.java new file mode 100644 index 0000000000..b9d1bb68ff --- /dev/null +++ b/src/interfaces/jdbc/org/postgresql/util/PGtokenizer.java @@ -0,0 +1,197 @@ +package org.postgresql.util; + +import java.sql.*; +import java.util.*; + +/** + * This class is used to tokenize the text output of org.postgres. + * + *

It's mainly used by the geometric classes, but is useful in parsing any + * output from custom data types output from org.postgresql. + * + * @see org.postgresql.geometric.PGbox + * @see org.postgresql.geometric.PGcircle + * @see org.postgresql.geometric.PGlseg + * @see org.postgresql.geometric.PGpath + * @see org.postgresql.geometric.PGpoint + * @see org.postgresql.geometric.PGpolygon + */ +public class PGtokenizer +{ + // Our tokens + protected Vector tokens; + + /** + * Create a tokeniser. + * + *

We could have used StringTokenizer to do this, however, we needed to + * handle nesting of '(' ')' '[' ']' '<' and '>' as these are used + * by the geometric data types. + * + * @param string containing tokens + * @param delim single character to split the tokens + */ + public PGtokenizer(String string,char delim) + { + tokenize(string,delim); + } + + /** + * This resets this tokenizer with a new string and/or delimiter. + * + * @param string containing tokens + * @param delim single character to split the tokens + */ + public int tokenize(String string,char delim) + { + tokens = new Vector(); + + // nest holds how many levels we are in the current token. + // if this is > 0 then we don't split a token when delim is matched. + // + // The Geometric datatypes use this, because often a type may have others + // (usualls PGpoint) imbedded within a token. + // + // Peter 1998 Jan 6 - Added < and > to the nesting rules + int nest=0,p,s; + + for(p=0,s=0;p') + nest--; + + if(nest==0 && c==delim) { + tokens.addElement(string.substring(s,p)); + s=p+1; // +1 to skip the delimiter + } + + } + + // Don't forget the last token ;-) + if(s"); + } + + /** + * Removes < and > from the beginning and end of all tokens + * @return String without the < or > + */ + public void removeAngle() + { + remove("<",">"); + } +} -- cgit v1.2.1