Mercurial > jhg
diff src/org/tmatesoft/hg/util/Path.java @ 339:863356c2847e
Issue 16: respect glob patterns in HgIgnore for sub-directories
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Wed, 16 Nov 2011 22:42:21 +0100 |
parents | a415fe296a50 |
children | 12f668401613 |
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/util/Path.java Tue Nov 15 04:47:03 2011 +0100 +++ b/src/org/tmatesoft/hg/util/Path.java Wed Nov 16 22:42:21 2011 +0100 @@ -17,6 +17,8 @@ package org.tmatesoft.hg.util; import java.util.Collection; +import java.util.Iterator; +import java.util.NoSuchElementException; /** * Identify repository files (not String nor io.File). Convenient for pattern matching. Memory-friendly. @@ -61,6 +63,43 @@ public String toString() { return path; // CharSequence demands toString() impl } + + public Iterable<String> segments() { + class SegSeq implements Iterable<String>, Iterator<String> { + private int pos; // first char to return + + public Iterator<String> iterator() { + reset(); + return this; + } + public boolean hasNext() { + return pos < path.length(); + } + public String next() { + if (pos >= path.length()) { + throw new NoSuchElementException(); + } + int x = path.indexOf('/', pos); + if (x == -1) { + String rv = path.substring(pos); + pos = path.length(); + return rv; + } else { + String rv = path.substring(pos, x); + pos = x+1; + return rv; + } + } + public void remove() { + throw new UnsupportedOperationException(); + } + + private void reset() { + pos = 0; + } + }; + return new SegSeq(); + } public int compareTo(Path o) { return path.compareTo(o.path);