diff --git a/projects/samskivert/src/java/com/samskivert/util/StringUtil.java b/projects/samskivert/src/java/com/samskivert/util/StringUtil.java index 06143c9f..8891f7c7 100644 --- a/projects/samskivert/src/java/com/samskivert/util/StringUtil.java +++ b/projects/samskivert/src/java/com/samskivert/util/StringUtil.java @@ -1,5 +1,5 @@ // -// $Id: StringUtil.java,v 1.39 2002/10/16 00:44:48 mdb Exp $ +// $Id: StringUtil.java,v 1.40 2002/10/31 01:24:10 shaper Exp $ // // samskivert library - useful routines for java programs // Copyright (C) 2001 Michael Bayne @@ -698,14 +698,35 @@ public class StringUtil return tokens; } + /** + * Joins an array of strings into a single string separated by commas. + */ + public static String join (String[] values) + { + return joinEscaped(values, false); + } + /** * Joins an array of strings into a single string, separated by * commas, and escaping commas that occur in the individual string * values such that a subsequent call to {@link #parseStringArray} - * would recreated the string array properly. Any elements in the + * would recreate the string array properly. Any elements in the * values array that are null will be treated as an empty string. */ public static String joinEscaped (String[] values) + { + return joinEscaped(values, true); + } + + /** + * Joins an array of strings into a single string, separated by + * commas, and optionally escaping commas that occur in the individual + * string values such that a subsequent call to {@link + * #parseStringArray} would recreate the string array properly. Any + * elements in the values array that are null will be treated as an + * empty string. + */ + public static String joinEscaped (String[] values, boolean escape) { StringBuffer buf = new StringBuffer(); int vlength = values.length; @@ -714,7 +735,7 @@ public class StringUtil buf.append(", "); } String value = (values[i] == null) ? "" : values[i]; - buf.append(replace(value, ",", ",,")); + buf.append((escape) ? replace(value, ",", ",,") : value); } return buf.toString(); }