Author: rhauch
Date: 2008-12-04 16:33:19 -0500 (Thu, 04 Dec 2008)
New Revision: 653
Modified:
trunk/dna-common/src/main/java/org/jboss/dna/common/util/StringUtil.java
Log:
Added another utility method that complements 'splitLines(String)'.
Modified: trunk/dna-common/src/main/java/org/jboss/dna/common/util/StringUtil.java
===================================================================
--- trunk/dna-common/src/main/java/org/jboss/dna/common/util/StringUtil.java 2008-12-03
22:46:57 UTC (rev 652)
+++ trunk/dna-common/src/main/java/org/jboss/dna/common/util/StringUtil.java 2008-12-04
21:33:19 UTC (rev 653)
@@ -46,6 +46,36 @@
private static final Pattern PARAMETER_COUNT_PATTERN =
Pattern.compile("\\{(\\d+)\\}");
/**
+ * Combine the lines into a single string, using the new line character as the
delimiter. This is compatible with
+ * {@link #splitLines(String)}.
+ *
+ * @param lines the lines to be combined
+ * @return the combined lines, or an empty string if there are no lines
+ */
+ public static String combineLines( String[] lines ) {
+ return combineLines(lines, '\n');
+ }
+
+ /**
+ * Combine the lines into a single string, using the supplied separator as the
delimiter.
+ *
+ * @param lines the lines to be combined
+ * @param separator the separator character
+ * @return the combined lines, or an empty string if there are no lines
+ */
+ public static String combineLines( String[] lines,
+ char separator ) {
+ if (lines == null || lines.length == 0) return "";
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i != lines.length; ++i) {
+ String line = lines[i];
+ if (i != 0) sb.append(separator);
+ sb.append(line);
+ }
+ return sb.toString();
+ }
+
+ /**
* Split the supplied content into lines, returning each line as an element in the
returned list.
*
* @param content the string content that is to be split
Show replies by date