2012-06-08 15:28:36 +02:00
|
|
|
package com.Acrobot.Breeze.Utils;
|
|
|
|
|
2012-10-21 22:46:00 +02:00
|
|
|
import org.apache.commons.lang.WordUtils;
|
2015-05-31 18:27:11 +02:00
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2017-09-23 16:19:00 +02:00
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Collection;
|
2015-05-31 18:27:11 +02:00
|
|
|
import java.util.List;
|
2017-09-23 16:19:00 +02:00
|
|
|
import java.util.stream.Collectors;
|
2012-10-21 22:46:00 +02:00
|
|
|
|
2012-06-08 15:28:36 +02:00
|
|
|
/**
|
|
|
|
* @author Acrobot
|
|
|
|
*/
|
|
|
|
public class StringUtil {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Capitalizes every first letter of a word
|
|
|
|
*
|
|
|
|
* @param string String to reformat
|
|
|
|
* @param separator Word separator
|
|
|
|
* @return Reformatted string
|
|
|
|
*/
|
|
|
|
public static String capitalizeFirstLetter(String string, char separator) {
|
2012-11-29 20:28:16 +01:00
|
|
|
char[] separators = new char[]{separator};
|
2012-06-08 15:28:36 +02:00
|
|
|
|
2012-11-23 21:01:53 +01:00
|
|
|
return WordUtils.capitalizeFully(string, separators).replace(String.valueOf(separator), " ");
|
2012-06-08 15:28:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Capitalizes every first letter of a word
|
|
|
|
*
|
|
|
|
* @param string String to reformat
|
|
|
|
* @return Reformatted string
|
|
|
|
* @see com.Acrobot.Breeze.Utils.StringUtil#capitalizeFirstLetter(String, char)
|
|
|
|
*/
|
|
|
|
public static String capitalizeFirstLetter(String string) {
|
|
|
|
return capitalizeFirstLetter(string, ' ');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Joins a String array
|
|
|
|
*
|
|
|
|
* @param array array to join
|
|
|
|
* @return Joined array
|
|
|
|
*/
|
|
|
|
public static String joinArray(String[] array) {
|
2017-09-23 16:19:00 +02:00
|
|
|
return joinArray(Arrays.asList(array));
|
2012-06-08 15:28:36 +02:00
|
|
|
}
|
2013-10-27 16:48:43 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Joins an iterable
|
|
|
|
*
|
|
|
|
* @param array Iterable
|
|
|
|
* @return Joined iterable
|
|
|
|
*/
|
2017-09-23 16:19:00 +02:00
|
|
|
public static String joinArray(Collection<String> array) {
|
|
|
|
return array.stream().collect(Collectors.joining(" "));
|
2013-10-27 16:48:43 +01:00
|
|
|
}
|
2015-05-31 18:27:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Strips colour codes from a string
|
|
|
|
* @param string String to strip
|
|
|
|
* @return Stripped string
|
|
|
|
*/
|
|
|
|
public static String stripColourCodes(String string) {
|
|
|
|
return ChatColor.stripColor(string);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stips colour codes from an array of strings
|
|
|
|
* @param strings Strings to strip the codes from
|
|
|
|
* @return Stripped strings
|
|
|
|
*/
|
|
|
|
public static String[] stripColourCodes(String[] strings) {
|
|
|
|
List<String> output = new ArrayList<String>();
|
|
|
|
|
|
|
|
for (String string : strings) {
|
|
|
|
output.add(stripColourCodes(string));
|
|
|
|
}
|
|
|
|
|
|
|
|
return output.toArray(new String[output.size()]);
|
|
|
|
}
|
2012-06-08 15:28:36 +02:00
|
|
|
}
|