add utility method to check whether a string is valid hexadecimal number
This commit is contained in:
parent
68ec11a4e9
commit
85073f7f5b
@ -3,6 +3,7 @@ package de.marhali.easyi18n.util;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* String utilities
|
* String utilities
|
||||||
@ -10,6 +11,17 @@ import java.io.StringWriter;
|
|||||||
*/
|
*/
|
||||||
public class StringUtil {
|
public class StringUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the provided String represents a hexadecimal number.
|
||||||
|
* For example: {@code 0x100...}, {@code -0x100...} and {@code +0x100...}.
|
||||||
|
* @param string String to evaluate
|
||||||
|
* @return true if hexadecimal string otherwise false
|
||||||
|
*/
|
||||||
|
public static boolean isHexString(@NotNull String string) {
|
||||||
|
final Pattern hexNumberPattern = Pattern.compile("[+-]?0[xX][0-9a-fA-F]+");
|
||||||
|
return hexNumberPattern.matcher(string).matches();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Escapes control characters for the given input string.
|
* Escapes control characters for the given input string.
|
||||||
* Inspired by Apache Commons (see {@link org.apache.commons.lang.StringEscapeUtils}
|
* Inspired by Apache Commons (see {@link org.apache.commons.lang.StringEscapeUtils}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user