fixed copyright headers
authorSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Sun, 28 Jul 2013 17:35:35 +0000 (20:35 +0300)
committerSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Sun, 28 Jul 2013 17:35:35 +0000 (20:35 +0300)
27 files changed:
src/main/java/eu/svjatoslav/commons/commandline/CLIHelper.java
src/main/java/eu/svjatoslav/commons/commandline/parameterparser/Argument.java
src/main/java/eu/svjatoslav/commons/commandline/parameterparser/Parameter.java
src/main/java/eu/svjatoslav/commons/commandline/parameterparser/Parser.java
src/main/java/eu/svjatoslav/commons/commandline/parameterparser/arguments/ExistingDirectory.java
src/main/java/eu/svjatoslav/commons/commandline/parameterparser/arguments/ExistingFile.java
src/main/java/eu/svjatoslav/commons/commandline/parameterparser/arguments/IntegerArgument.java
src/main/java/eu/svjatoslav/commons/commandline/parameterparser/arguments/NonExistingDirectory.java
src/main/java/eu/svjatoslav/commons/commandline/parameterparser/arguments/NonExistingFile.java
src/main/java/eu/svjatoslav/commons/commandline/parameterparser/arguments/StringArgument.java
src/main/java/eu/svjatoslav/commons/data/BitInputStream.java
src/main/java/eu/svjatoslav/commons/data/BitOutputStream.java
src/main/java/eu/svjatoslav/commons/data/EnhancedDataInputStream.java
src/main/java/eu/svjatoslav/commons/data/EnhancedDataOutputStream.java
src/main/java/eu/svjatoslav/commons/data/HexConverter.java
src/main/java/eu/svjatoslav/commons/data/xml/XmlElement.java
src/main/java/eu/svjatoslav/commons/data/xml/XmlHelper.java
src/main/java/eu/svjatoslav/commons/file/CommonPathResolver.java
src/main/java/eu/svjatoslav/commons/file/FilePathParser.java
src/main/java/eu/svjatoslav/commons/file/IOHelper.java
src/main/java/eu/svjatoslav/commons/gui/dialog/ExceptionDialog.java
src/main/java/eu/svjatoslav/commons/string/CuttableString.java
src/main/java/eu/svjatoslav/commons/string/WildCardMatcher.java
src/main/java/eu/svjatoslav/commons/string/tokenizer/InvalidSyntaxException.java [new file with mode: 0644]
src/main/java/eu/svjatoslav/commons/string/tokenizer/Terminator.java [new file with mode: 0644]
src/main/java/eu/svjatoslav/commons/string/tokenizer/Tokenizer.java [new file with mode: 0644]
src/main/java/eu/svjatoslav/commons/string/tokenizer/TokenizerMatch.java [new file with mode: 0644]

index a232246..5537df8 100755 (executable)
@@ -1,6 +1,6 @@
 /*
  * Svjatoslav Commons - shared library of common functionality.
- * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ * Copyright ©2012-2013, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
  * 
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of version 2 of the GNU General Public License
index d969f16..36d2c92 100755 (executable)
@@ -1,6 +1,6 @@
 /*
  * Svjatoslav Commons - shared library of common functionality.
- * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ * Copyright ©2012-2013, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
  * 
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of version 2 of the GNU General Public License
index 1575fcf..1e738a5 100755 (executable)
@@ -1,6 +1,6 @@
 /*
  * Svjatoslav Commons - shared library of common functionality.
- * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ * Copyright ©2012-2013, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
  * 
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of version 2 of the GNU General Public License
@@ -51,9 +51,8 @@ public class Parameter {
                // save aliases
                {
                        final ArrayList<String> aliasesList = new ArrayList<String>();
-                       for (final String alias : aliases) {
+                       for (final String alias : aliases)
                                aliasesList.add(alias);
-                       }
                        this.aliases = aliasesList;
                }
 
@@ -112,26 +111,23 @@ public class Parameter {
        }
 
        public File getArgumentAsFile() {
-               if (arguments.size() != 1) {
+               if (arguments.size() != 1)
                        throw new RuntimeException("Parameter " + description
                                        + " shall have exactly 1 argument.");
-               }
                return new File(arguments.get(0));
        }
 
        public int getArgumentAsInteger() {
-               if (arguments.size() != 1) {
+               if (arguments.size() != 1)
                        throw new RuntimeException("Parameter " + description
                                        + " shall have exactly 1 argument.");
-               }
                return Integer.parseInt(arguments.get(0));
        }
 
        public String getArgumentAsString() {
-               if (arguments.size() != 1) {
+               if (arguments.size() != 1)
                        throw new RuntimeException("Parameter " + description
                                        + " shall have exactly 1 argument.");
-               }
                return arguments.get(0);
        }
 
@@ -149,9 +145,8 @@ public class Parameter {
        public List<Integer> getArgumentsAsIntegers() {
                final ArrayList<Integer> result = new ArrayList<Integer>();
 
-               for (final String argument : arguments) {
+               for (final String argument : arguments)
                        result.add(Integer.valueOf(argument));
-               }
 
                return result;
        }
@@ -169,9 +164,8 @@ public class Parameter {
                if (enableArguments) {
                        buffer.append(" (" + argumentType.describeFormat() + ")");
 
-                       if (enableMultipleArguments) {
+                       if (enableMultipleArguments)
                                buffer.append("...");
-                       }
                }
                buffer.append("\n");
 
index d2f623f..a72984f 100755 (executable)
@@ -1,6 +1,6 @@
 /*
  * Svjatoslav Commons - shared library of common functionality.
- * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ * Copyright ©2012-2013, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
  * 
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of version 2 of the GNU General Public License
@@ -30,10 +30,9 @@ public class Parser {
         */
        public Parameter getParameterByAlias(final String alias) {
 
-               for (final Parameter parameter : parameters) {
+               for (final Parameter parameter : parameters)
                        if (parameter.matchesAlias(alias))
                                return parameter;
-               }
 
                return null;
        }
@@ -60,10 +59,9 @@ public class Parser {
                                        return false;
 
                        } else {
-                               if (currentParameter != null) {
+                               if (currentParameter != null)
                                        if (!currentParameter.noMoreArguments())
                                                return false;
-                               }
 
                                parameterForAlias.setParameterSpecified(true);
                                currentParameter = parameterForAlias;
@@ -73,21 +71,19 @@ public class Parser {
 
                // check if any mandatory parameters are missing
 
-               for (final Parameter parameter : parameters) {
+               for (final Parameter parameter : parameters)
                        if (parameter.isMandatory() && (!parameter.isParameterSpecified())) {
                                System.out.println("Error! Mandatory parameter ("
                                                + parameter.getAliases() + ") is not specified.");
                                return false;
                        }
-               }
 
                return true;
        }
 
        public void showHelp() {
-               for (final Parameter parameter : parameters) {
+               for (final Parameter parameter : parameters)
                        System.out.println(parameter.getHelp());
-               }
        }
 
 }
index 25c521d..07341dd 100755 (executable)
@@ -1,6 +1,6 @@
 /*
  * Svjatoslav Commons - shared library of common functionality.
- * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ * Copyright ©2012-2013, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
  * 
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of version 2 of the GNU General Public License
index d46f05d..676663f 100755 (executable)
@@ -1,6 +1,6 @@
 /*
  * Svjatoslav Commons - shared library of common functionality.
- * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ * Copyright ©2012-2013, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
  * 
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of version 2 of the GNU General Public License
index 50f1ece..1d29046 100755 (executable)
@@ -1,6 +1,6 @@
 /*
  * Svjatoslav Commons - shared library of common functionality.
- * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ * Copyright ©2012-2013, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
  * 
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of version 2 of the GNU General Public License
index 3190e9d..005077b 100755 (executable)
@@ -1,6 +1,6 @@
 /*
  * Svjatoslav Commons - shared library of common functionality.
- * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ * Copyright ©2012-2013, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
  * 
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of version 2 of the GNU General Public License
index 1f68bf8..e4ddeb4 100755 (executable)
@@ -1,6 +1,6 @@
 /*
  * Svjatoslav Commons - shared library of common functionality.
- * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ * Copyright ©2012-2013, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
  * 
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of version 2 of the GNU General Public License
index 0da8cb7..dd9f588 100755 (executable)
@@ -1,6 +1,6 @@
 /*
  * Svjatoslav Commons - shared library of common functionality.
- * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ * Copyright ©2012-2013, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
  * 
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of version 2 of the GNU General Public License
index 3ecff98..6564417 100755 (executable)
@@ -1,6 +1,6 @@
 /*
  * Svjatoslav Commons - shared library of common functionality.
- * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ * Copyright ©2012-2013, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
  * 
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of version 2 of the GNU General Public License
@@ -44,9 +44,8 @@ public class BitInputStream {
 
                        final int currentBit = currentByte & mask;
 
-                       if (currentBit != 0) {
+                       if (currentBit != 0)
                                readableByte = readableByte | 1;
-                       }
 
                        currentBytePointer--;
                }
@@ -54,11 +53,10 @@ public class BitInputStream {
        }
 
        public int readIntegerCompressed8() throws IOException {
-               if (readBits(1) == 0) {
+               if (readBits(1) == 0)
                        return readBits(8);
-               } else {
+               else
                        return readBits(32);
-               }
        }
 
 }
index 6348d0a..293788f 100755 (executable)
@@ -1,6 +1,6 @@
 /*
  * Svjatoslav Commons - shared library of common functionality.
- * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ * Copyright ©2012-2013, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
  * 
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of version 2 of the GNU General Public License
@@ -46,9 +46,8 @@ public class BitOutputStream {
                        final int currentBit = data & mask;
                        currentByte = currentByte << 1;
 
-                       if (currentBit != 0) {
+                       if (currentBit != 0)
                                currentByte = currentByte | 1;
-                       }
                        currentBytePointer++;
 
                        if (currentBytePointer == 8) {
index 4adc080..e093619 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Svjatoslav Commons - shared library of common functionality.
- * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ * Copyright ©2012-2013, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
  * 
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of version 2 of the GNU General Public License
index 2598215..24e8029 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Svjatoslav Commons - shared library of common functionality.
- * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ * Copyright ©2012-2013, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
  * 
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of version 2 of the GNU General Public License
index 52b16f4..e2f2007 100644 (file)
@@ -1,19 +1,28 @@
+/*
+ * Svjatoslav Commons - shared library of common functionality.
+ * Copyright ©2012-2013, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ * 
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public License
+ * as published by the Free Software Foundation.
+ */
+
 package eu.svjatoslav.commons.data;
 
 public class HexConverter {
 
-       static final String hexCodes = "0123456789ABCDEF";
+       static final String hexCharacters = "0123456789ABCDEF";
 
-       public static String byteArrayToHex(final byte[] raw) {
+       public static String byteArrayToHex(final byte[] bytes) {
 
-               if (raw == null)
+               if (bytes == null)
                        return null;
 
-               final StringBuilder result = new StringBuilder(2 * raw.length);
+               final StringBuilder result = new StringBuilder(2 * bytes.length);
 
-               for (final byte b : raw)
-                       result.append(hexCodes.charAt((b & 0xF0) >> 4)).append(
-                                       hexCodes.charAt((b & 0x0F)));
+               for (final byte b : bytes)
+                       result.append(hexCharacters.charAt((b & 0xF0) >> 4)).append(
+                                       hexCharacters.charAt((b & 0x0F)));
 
                return result.toString();
        }
index 7b807ac..71e8a95 100644 (file)
@@ -1,3 +1,12 @@
+/*
+ * Svjatoslav Commons - shared library of common functionality.
+ * Copyright ©2012-2013, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ * 
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public License
+ * as published by the Free Software Foundation.
+ */
+
 package eu.svjatoslav.commons.data.xml;
 
 import java.util.ArrayList;
index 94b977d..355ec2c 100644 (file)
@@ -1,3 +1,11 @@
+/*
+ * Svjatoslav Commons - shared library of common functionality.
+ * Copyright ©2012-2013, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ * 
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public License
+ * as published by the Free Software Foundation.
+ */
 package eu.svjatoslav.commons.data.xml;
 
 import java.io.IOException;
index 81f9213..1fa1cfd 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Svjatoslav Commons - shared library of common functionality.
- * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ * Copyright ©2012-2013, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
  * 
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of version 2 of the GNU General Public License
@@ -13,6 +13,10 @@ import java.io.File;
 
 public class CommonPathResolver {
 
+       /**
+        * This method tries to guess user desktop directory. Implementation is
+        * pretty lousy. Need to improve it some day.
+        */
        public static File getDesktopDirectory() {
                String desktopPath = System.getProperty("user.home") + "/Desktop";
 
index 3fa1894..ac3856b 100755 (executable)
@@ -1,6 +1,6 @@
 /*
  * Svjatoslav Commons - shared library of common functionality.
- * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ * Copyright ©2012-2013, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
  * 
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of version 2 of the GNU General Public License
index 97d3b44..a6dd05f 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Svjatoslav Commons - shared library of common functionality.
- * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ * Copyright ©2012-2013, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
  * 
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of version 2 of the GNU General Public License
index a80e6e3..c951916 100755 (executable)
@@ -1,6 +1,6 @@
 /*
  * Svjatoslav Commons - shared library of common functionality.
- * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ * Copyright ©2012-2013, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
  * 
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of version 2 of the GNU General Public License
@@ -19,6 +19,18 @@ import javax.swing.JPanel;
 
 public class ExceptionDialog {
 
+       /**
+        * This method is for testing
+        */
+       public static void main(final String[] args) {
+
+               final Throwable cause = new Throwable("details.....");
+
+               final Exception exception = new Exception("test", cause);
+
+               new ExceptionDialog(exception);
+       }
+
        public ExceptionDialog(final Exception exception) {
                showException(exception);
        }
@@ -91,16 +103,4 @@ public class ExceptionDialog {
 
        }
 
-       /**
-        * This method is for testing
-        */
-       public static void main(final String[] args) {
-
-               final Throwable cause = new Throwable("details.....");
-
-               final Exception exception = new Exception("test", cause);
-
-               new ExceptionDialog(exception);
-       }
-
 }
index 2adeba2..6fd0707 100644 (file)
@@ -1,3 +1,12 @@
+/*
+ * Svjatoslav Commons - shared library of common functionality.
+ * Copyright ©2012-2013, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ * 
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public License
+ * as published by the Free Software Foundation.
+ */
+
 package eu.svjatoslav.commons.string;
 
 public class CuttableString {
index 0da2309..6e3031d 100755 (executable)
@@ -1,6 +1,6 @@
 /*
  * Svjatoslav Commons - shared library of common functionality.
- * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ * Copyright ©2012-2013, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
  * 
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of version 2 of the GNU General Public License
diff --git a/src/main/java/eu/svjatoslav/commons/string/tokenizer/InvalidSyntaxException.java b/src/main/java/eu/svjatoslav/commons/string/tokenizer/InvalidSyntaxException.java
new file mode 100644 (file)
index 0000000..0856b5f
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * Svjatoslav Commons - shared library of common functionality.
+ * Copyright ©2012-2013, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ * 
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public License
+ * as published by the Free Software Foundation.
+ */
+
+package eu.svjatoslav.commons.string.tokenizer;
+
+public class InvalidSyntaxException extends Exception {
+
+       private static final long serialVersionUID = 88294980027680555L;
+
+       public InvalidSyntaxException(final String cause) {
+               super(cause);
+       }
+
+}
diff --git a/src/main/java/eu/svjatoslav/commons/string/tokenizer/Terminator.java b/src/main/java/eu/svjatoslav/commons/string/tokenizer/Terminator.java
new file mode 100644 (file)
index 0000000..14fcbb5
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Svjatoslav Commons - shared library of common functionality.
+ * Copyright ©2012-2013, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ * 
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public License
+ * as published by the Free Software Foundation.
+ */
+
+package eu.svjatoslav.commons.string.tokenizer;
+
+public class Terminator {
+
+       String startSequence;
+       String endSequence;
+       boolean ignoreTerminator;
+
+       public Terminator(final String startPattern, final boolean ignoreTerminator) {
+               startSequence = startPattern;
+               this.ignoreTerminator = ignoreTerminator;
+       }
+
+       public Terminator(final String startSequence, final String endSequence,
+                       final boolean ignoreTerminator) {
+
+               this.startSequence = startSequence;
+               this.endSequence = endSequence;
+               this.ignoreTerminator = ignoreTerminator;
+       }
+
+}
diff --git a/src/main/java/eu/svjatoslav/commons/string/tokenizer/Tokenizer.java b/src/main/java/eu/svjatoslav/commons/string/tokenizer/Tokenizer.java
new file mode 100644 (file)
index 0000000..dc0cb9c
--- /dev/null
@@ -0,0 +1,129 @@
+/*
+ * Svjatoslav Commons - shared library of common functionality.
+ * Copyright ©2012-2013, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ * 
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public License
+ * as published by the Free Software Foundation.
+ */
+
+package eu.svjatoslav.commons.string.tokenizer;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Stack;
+
+public class Tokenizer {
+
+       private final List<Terminator> terminators = new ArrayList<Terminator>();
+       private final String source;
+
+       Stack<Integer> tokenIndexes = new Stack<Integer>();
+
+       private int currentIndex = 0;
+
+       public Tokenizer(final String source) {
+               this.source = source;
+       }
+
+       public void addTerminator(final String startSequence,
+                       final boolean ignoreTerminator) {
+               terminators.add(new Terminator(startSequence, ignoreTerminator));
+       }
+
+       public void addTerminator(final String startSequence,
+                       final String endSequence, final boolean ignoreTerminator) {
+               terminators.add(new Terminator(startSequence, endSequence,
+                               ignoreTerminator));
+       }
+
+       public void expectNextToken(final String value)
+                       throws InvalidSyntaxException {
+               final TokenizerMatch match = getNextToken();
+               if (!value.equals(match.token))
+                       throw new InvalidSyntaxException("Expected \"" + value
+                                       + "\" but got \"" + match.token + "\" instead.");
+       }
+
+       public TokenizerMatch getNextToken() {
+               tokenIndexes.push(currentIndex);
+               final StringBuffer result = new StringBuffer();
+
+               while (true) {
+                       if (currentIndex >= source.length())
+                               return null;
+
+                       boolean accumulateCurrentChar = true;
+
+                       findTerminator: for (final Terminator terminator : terminators)
+                               if (sequenceMatches(terminator.startSequence))
+
+                                       if (terminator.ignoreTerminator) {
+                                               currentIndex += terminator.startSequence.length();
+
+                                               if (terminator.endSequence != null)
+                                                       skipUntilSequence(terminator.endSequence);
+
+                                               if (result.length() > 0)
+                                                       return new TokenizerMatch(result.toString(),
+                                                                       terminator);
+                                               else {
+                                                       accumulateCurrentChar = false;
+                                                       break findTerminator;
+                                               }
+                                       } else if (result.length() > 0)
+                                               return new TokenizerMatch(result.toString(), terminator);
+                                       else {
+                                               currentIndex += terminator.startSequence.length();
+                                               return new TokenizerMatch(terminator.startSequence,
+                                                               terminator);
+                                       }
+
+                       if (accumulateCurrentChar) {
+                               result.append(source.charAt(currentIndex));
+                               currentIndex++;
+                       }
+               }
+
+       }
+
+       public boolean probeNextToken(final String token) {
+               if (token.equals(getNextToken().token))
+                       return true;
+
+               unreadToken();
+               return false;
+       }
+
+       public boolean sequenceMatches(final String sequence) {
+               if ((currentIndex + sequence.length()) > source.length())
+                       return false;
+
+               for (int i = 0; i < sequence.length(); i++)
+                       if (sequence.charAt(i) != source.charAt(i + currentIndex))
+                               return false;
+
+               return true;
+       }
+
+       public void skipUntilDataEnd() {
+               tokenIndexes.push(currentIndex);
+               currentIndex = source.length();
+       }
+
+       public void skipUntilSequence(final String sequence) {
+               while (currentIndex < source.length()) {
+                       if (sequenceMatches(sequence)) {
+                               currentIndex += sequence.length();
+                               return;
+                       }
+
+                       currentIndex++;
+               }
+       }
+
+       public void unreadToken() {
+               currentIndex = tokenIndexes.pop();
+       }
+
+}
diff --git a/src/main/java/eu/svjatoslav/commons/string/tokenizer/TokenizerMatch.java b/src/main/java/eu/svjatoslav/commons/string/tokenizer/TokenizerMatch.java
new file mode 100644 (file)
index 0000000..439eb2a
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * Svjatoslav Commons - shared library of common functionality.
+ * Copyright ©2012-2013, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ * 
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public License
+ * as published by the Free Software Foundation.
+ */
+
+package eu.svjatoslav.commons.string.tokenizer;
+
+public class TokenizerMatch {
+
+       public String token;
+       public Terminator terminator;
+
+       public TokenizerMatch(final String token, final Terminator terminator) {
+               this.token = token;
+               this.terminator = terminator;
+       }
+}