From a2dac2c78d1fff0b2cedadcdaac030001eb851ac Mon Sep 17 00:00:00 2001 From: Tomasz Zarna Date: Fri, 23 Mar 2012 09:10:41 +0100 Subject: Allow to write tests with CLI syntax CQ: 6385 Bug: 365444 Change-Id: I2d5164cd92429673fe3c37e9f5f9bc565192cc12 Signed-off-by: Matthias Sohn --- org.eclipse.jgit/src/org/eclipse/jgit/util/IO.java | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/util') diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/IO.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/IO.java index fab86025dc..910d982015 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/IO.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/IO.java @@ -54,6 +54,8 @@ import java.io.InputStream; import java.nio.ByteBuffer; import java.nio.channels.ReadableByteChannel; import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.List; import org.eclipse.jgit.internal.JGitText; @@ -331,6 +333,42 @@ public class IO { } } + /** + * Divides the given string into lines. + * + * @param s + * the string to read + * @return the string divided into lines + */ + public static List readLines(final String s) { + List l = new ArrayList(); + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < s.length(); i++) { + char c = s.charAt(i); + if (c == '\n') { + l.add(sb.toString()); + sb.setLength(0); + continue; + } + if (c == '\r') { + if (i + 1 < s.length()) { + c = s.charAt(++i); + l.add(sb.toString()); + sb.setLength(0); + if (c != '\n') + sb.append(c); + continue; + } else { // EOF + l.add(sb.toString()); + break; + } + } + sb.append(c); + } + l.add(sb.toString()); + return l; + } + private IO() { // Don't create instances of a static only utility. } -- cgit v1.2.3