[jsemver] 79/95: Make refactoring, small improvements

Alexandre Viau reazem-guest at moszumanska.debian.org
Mon Feb 16 14:58:32 UTC 2015


This is an automated email from the git hooks/post-receive script.

reazem-guest pushed a commit to branch master
in repository jsemver.

commit 229a732976ce99801bee0d76f118ae201e21c1d2
Author: Zafar Khaja <zafarkhaja at gmail.com>
Date:   Mon Feb 3 10:05:26 2014 +0400

    Make refactoring, small improvements
---
 .../github/zafarkhaja/semver/VersionParser.java    | 29 ++++++++++++----------
 1 file changed, 16 insertions(+), 13 deletions(-)

diff --git a/src/main/java/com/github/zafarkhaja/semver/VersionParser.java b/src/main/java/com/github/zafarkhaja/semver/VersionParser.java
index 083e774..62305e0 100644
--- a/src/main/java/com/github/zafarkhaja/semver/VersionParser.java
+++ b/src/main/java/com/github/zafarkhaja/semver/VersionParser.java
@@ -309,8 +309,8 @@ class VersionParser implements Parser<Version> {
      */
     private MetadataVersion parsePreRelease() {
         List<String> idents = new ArrayList<String>();
-        CharType end = closestEndpoint(PLUS, EOL);
-        CharType before = closestEndpoint(DOT, end);
+        CharType end = nearestCharType(PLUS, EOL);
+        CharType before = nearestCharType(DOT, end);
         do {
             checkForEmptyIdentifier();
             if (chars.positiveLookaheadBefore(before, LETTER, HYPHEN)) {
@@ -320,7 +320,7 @@ class VersionParser implements Parser<Version> {
             }
             if (before == DOT) {
                 chars.consume(DOT);
-                before = closestEndpoint(DOT, end);
+                before = nearestCharType(DOT, end);
             }
         } while (!chars.positiveLookahead(end));
         return new MetadataVersion(idents.toArray(new String[idents.size()]));
@@ -347,7 +347,7 @@ class VersionParser implements Parser<Version> {
     private MetadataVersion parseBuild() {
         List<String> idents = new ArrayList<String>();
         CharType end = EOL;
-        CharType before = closestEndpoint(DOT, end);
+        CharType before = nearestCharType(DOT, end);
         do {
             checkForEmptyIdentifier();
             if (chars.positiveLookaheadBefore(before, LETTER, HYPHEN)) {
@@ -357,7 +357,7 @@ class VersionParser implements Parser<Version> {
             }
             if (before == DOT) {
                 chars.consume(DOT);
-                before = closestEndpoint(DOT, end);
+                before = nearestCharType(DOT, end);
             }
         } while (!chars.positiveLookahead(end));
         return new MetadataVersion(idents.toArray(new String[idents.size()]));
@@ -425,17 +425,20 @@ class VersionParser implements Parser<Version> {
     }
 
     /**
-     * Chooses the closest character.
+     * Finds the nearest character type.
      *
-     * @param tryThis the character to try first
-     * @param orThis the character to fallback to
-     * @return the closest character
+     * @param types the character types to choose from
+     * @return the nearest character type or {@code EOL}
      */
-    private CharType closestEndpoint(CharType tryThis, CharType orThis) {
-        if (chars.positiveLookaheadBefore(orThis, tryThis)) {
-            return tryThis;
+    private CharType nearestCharType(CharType... types) {
+        for (Character chr : chars) {
+            for (CharType type : types) {
+                if (type.isMatchedBy(chr)) {
+                    return type;
+                }
+            }
         }
-        return orThis;
+        return EOL;
     }
 
     /**

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/jsemver.git



More information about the pkg-java-commits mailing list