diff --git a/Frameworks/Core/ERExtensions/Sources/er/extensions/foundation/ERXStringUtilities.java b/Frameworks/Core/ERExtensions/Sources/er/extensions/foundation/ERXStringUtilities.java index c530e55dd7a..6526fda1871 100644 --- a/Frameworks/Core/ERExtensions/Sources/er/extensions/foundation/ERXStringUtilities.java +++ b/Frameworks/Core/ERExtensions/Sources/er/extensions/foundation/ERXStringUtilities.java @@ -413,7 +413,41 @@ public static Integer integerWithString(String s) { // ignore } return null; - } + } + + /** + * Wrapper for {@link Integer#valueOf(String)} that catches + * the NumberFormatException. + * + * @param s string to convert to an Integer + * @return Integer or null if the string could + * not be parsed + */ + public static Integer safeInteger(String s) { + try { + return Integer.valueOf(s); + } catch (NumberFormatException e) { + // ignore + } + return null; + } + + /** + * Wrapper for {@link Long#valueOf(String)} that catches + * the NumberFormatException. + * + * @param s string to convert to a Long + * @return Long or null if the string could + * not be parsed + */ + public static Long safeLong(String s) { + try { + return Long.valueOf(s); + } catch (NumberFormatException e) { + // ignore + } + return null; + } /** * Retrives a given string for a given name, extension