Java Code Examples for org.codehaus.groovy.runtime.StringGroovyMethods#replaceAll()

The following examples show how to use org.codehaus.groovy.runtime.StringGroovyMethods#replaceAll() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StringUtils.java    From groovy with Apache License 2.0 6 votes vote down vote up
public static String replaceStandardEscapes(String text) {
	if (!text.contains(BACKSLASH)) {
		return text;
	}

	String result = StringGroovyMethods.replaceAll((CharSequence) text, STANDARD_ESCAPES_PATTERN, new Closure<Void>(null, null) {
		Object doCall(String _0, String _1, String _2) {
			if (isLengthOdd(_1)) {
				return _0;
			}

			Character character = STANDARD_ESCAPES.get(_2.charAt(0));
			return _1 + (character != null ? character : _2);
		}
	});

	return replace(result,"\\\\", "\\");
}
 
Example 2
Source File: StringUtils.java    From groovy with Apache License 2.0 6 votes vote down vote up
private static String replaceLineEscape(String text) {
	if (!text.contains(BACKSLASH)) {
		return text;
	}

	text = StringGroovyMethods.replaceAll((CharSequence) text, LINE_ESCAPE_PATTERN, new Closure<Void>(null, null) {
		Object doCall(String _0, String _1) {
			if (isLengthOdd(_1)) {
				return _0;
			}

			return _1;
		}
	});

	return text;
}
 
Example 3
Source File: StringUtils.java    From groovy with Apache License 2.0 5 votes vote down vote up
public static String replaceHexEscapes(String text) {
	if (!text.contains(BACKSLASH)) {
		return text;
	}

	return StringGroovyMethods.replaceAll((CharSequence) text, HEX_ESCAPES_PATTERN, new Closure<Void>(null, null) {
		Object doCall(String _0, String _1, String _2) {
			if (isLengthOdd(_1)) {
				return _0;
			}

			return _1 + new String(Character.toChars(Integer.parseInt(_2, 16)));
		}
	});
}
 
Example 4
Source File: StringUtils.java    From groovy with Apache License 2.0 5 votes vote down vote up
public static String replaceOctalEscapes(String text) {
	if (!text.contains(BACKSLASH)) {
		return text;
	}

	return StringGroovyMethods.replaceAll((CharSequence) text, OCTAL_ESCAPES_PATTERN, new Closure<Void>(null, null) {
		Object doCall(String _0, String _1, String _2) {
			if (isLengthOdd(_1)) {
				return _0;
			}

			return _1 + new String(Character.toChars(Integer.parseInt(_2, 8)));
		}
	});
}