1 package net.sf.saxon.expr; 2 import net.sf.saxon.om.Item; 3 import net.sf.saxon.om.SequenceIterator; 4 import net.sf.saxon.value.StringValue; 5 6 import java.util.StringTokenizer ; 7 8 12 13 public class StringTokenIterator implements SequenceIterator { 14 15 private String theString; 16 private String delimiters; private StringTokenizer tokenizer; 18 private String current; 19 private int position = 0; 20 21 25 26 public StringTokenIterator (String string) { 27 theString = string; 28 delimiters = null; 29 tokenizer = new StringTokenizer (string); 30 } 31 32 37 38 public StringTokenIterator (String string, String delimiters) { 39 theString = string; 40 this.delimiters = delimiters; 41 tokenizer = new StringTokenizer (string, delimiters); 42 } 43 44 public Item next() { 45 if (tokenizer.hasMoreElements()) { 46 current = (String )tokenizer.nextElement(); 47 position++; 48 return new StringValue(current); 49 } else { 50 current = null; 51 position = -1; 52 return null; 53 } 54 } 55 56 public Item current() { 57 return (current == null ? null : new StringValue(current)); 58 } 59 60 public int position() { 61 return position; 62 } 63 64 public SequenceIterator getAnother() { 65 if (delimiters==null) { 66 return new StringTokenIterator(theString); 67 } else { 68 return new StringTokenIterator(theString, delimiters); 69 } 70 } 71 72 81 82 public int getProperties() { 83 return 0; 84 } 85 } 86 87 | Popular Tags |