package jcconf.groovy.script;

import static java.util.regex.Pattern.*;

import java.util.regex.Matcher;

import com.ibm.icu.text.Transliterator;

/**
 * TODO Add org.codehaus.groovy.runtime.ExtensionModule via java.util.ServiceLoader
 * 
 * @see META-INF/services/org.codehaus.groovy.runtime.ExtensionModule
 */
public class CustomFormatMethods {

	public static String getLower(String self) {
		return self.toLowerCase();
	}

	public static String getUpper(String self) {
		return self.toUpperCase();
	}

	public static String pad(String self, int length, String padding) {
		while (self.length() < length) {
			self = padding + self;
		}
		return self;
	}

	// TODO Add String.pad(int) extension method
	public static String pad(String self, int length) {
		return pad(self, length, "0");
	}

	// TODO Add Number.pad(int) extension method
	public static String pad(Number self, int length) {
		return pad(self.toString(), length, "0");
	}

	// TODO Add String.acronym extension method / property
	public static String getAcronym(String self) {
		Matcher matcher = compile("(?<=[&()+.,-;<=>?\\[\\]_{|}~ ]|^)[\\p{Alnum}]").matcher(self);

		StringBuilder buffer = new StringBuilder();
		while (matcher.find()) {
			buffer.append(matcher.group());
		}

		return buffer.toString();
	}

	// TODO Add String.pinyin extension method / property
	public static String getPinyin(String self) {
		return Transliterator.getInstance("Han-Latin").transform(self);
	}

}

@@ -1046,237 +1046,90 @@
 %7B%0A%09%09
-Matcher matcher = compile(%22(?%3C=%5B&()+.,-;%3C=%3E?%5C%5C%5B%5C%5C%5D_%7B%7C%7D~ %5D%7C%5E)%5B%5C%5Cp%7BAlnum%7D%5D%22).matcher(self);%0A%0A%09%09StringBuilder buffer = new StringBuilder();%0A%09%09while (matcher.find()) %7B%0A%09%09%09buffer.append(matcher.group());%0A%09%09%7D%0A%0A%09%09return buffer.toString(
+return compile(%22%5C%5CB.%7C%5C%5CP%7BL%7D%22, UNICODE_CHARACTER_CLASS).matcher(self).replaceAll(%22%22
 );%0A%09

Simplify String.acronym