aQute.lib.strings.Strings Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of biz.aQute.bndlib Show documentation
Show all versions of biz.aQute.bndlib Show documentation
bndlib: A Swiss Army Knife for OSGi
package aQute.lib.strings;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import aQute.lib.collections.ExtList;
public class Strings {
public static String join(String middle, Iterable< ? > objects) {
return join(middle, objects, null, null);
}
public static String join(Iterable< ? > objects) {
return join(",", objects, null, null);
}
public static String join(String middle, Iterable< ? > objects, Pattern pattern, String replace) {
StringBuilder sb = new StringBuilder();
join(sb, middle, objects, pattern, replace);
return sb.toString();
}
public static void join(StringBuilder sb, String middle, Iterable< ? > objects, Pattern pattern, String replace) {
String del = "";
if (objects == null)
return;
for (Object o : objects) {
if (o != null) {
sb.append(del);
String s = o.toString();
if (pattern != null) {
Matcher matcher = pattern.matcher(s);
if (!matcher.matches())
continue;
s = matcher.replaceAll(replace);
}
sb.append(s);
del = middle;
}
}
}
public static String join(String middle, Object[] segments) {
return join(middle, new ExtList