summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorTomasz Zarna <Tomasz.Zarna@pl.ibm.com>2012-03-23 09:10:41 +0100
committerMatthias Sohn <matthias.sohn@sap.com>2012-04-18 18:57:36 +0200
commita2dac2c78d1fff0b2cedadcdaac030001eb851ac (patch)
treecc22f3a9b9676b9349456e6b7585074ff6420383 /org.eclipse.jgit
parent95ed300b04f52e6d0625dfb5a6e0e52aac4bc412 (diff)
downloadjgit-a2dac2c78d1fff0b2cedadcdaac030001eb851ac.tar.gz
jgit-a2dac2c78d1fff0b2cedadcdaac030001eb851ac.zip
Allow to write tests with CLI syntax
CQ: 6385 Bug: 365444 Change-Id: I2d5164cd92429673fe3c37e9f5f9bc565192cc12 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/IO.java38
1 files changed, 38 insertions, 0 deletions
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<String> readLines(final String s) {
+ List<String> l = new ArrayList<String>();
+ 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.
}