|
|
@@ -8,6 +8,8 @@
|
|
|
package net.ranides.assira.text;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
+import java.io.StringReader;
|
|
|
+import java.io.UncheckedIOException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.Collection;
|
|
|
@@ -943,6 +945,27 @@ public final class StringUtils {
|
|
|
public static String escapeRE(String text) {
|
|
|
return REGEX_SPECIAL.matcher(text).replaceAll("\\\\$1");
|
|
|
}
|
|
|
+
|
|
|
+ public static List<String> lines(String text) {
|
|
|
+ try {
|
|
|
+ return IOStrings.readLines(new StringReader(text));
|
|
|
+ } catch (IOException e) {
|
|
|
+ // it shouldn't happpen
|
|
|
+ throw new UncheckedIOException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String asUnix(String text) {
|
|
|
+ return replace(replaceEndl(text), '\037', '\n');
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String asWindows(String text) {
|
|
|
+ return replace(replaceEndl(text), '\037', "\r\n");
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String replaceEndl(String text) {
|
|
|
+ return text.replaceAll("\r\n", "\037").replace('\n', '\037').replace('\r', '\037');
|
|
|
+ }
|
|
|
|
|
|
static void checkIndex(int size, int index) {
|
|
|
if( index<0 || index >= size ) {
|