Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/util/IO.java')
-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.
}

Back to the top