From 08127ebaddfb854c7c168fc76e4cf5f4f3d50c63 Mon Sep 17 00:00:00 2001 From: Piotr Jazdzyk Date: Sun, 25 Feb 2024 20:31:11 +0100 Subject: [PATCH] fix(SNSUNI-92): fix containsNonDigitChars() method, added exclusions for "-" and "e" to prevent false-positive condition for very low or very large numbers ie "1.0E-9" --- .../unitility/unitsystem/util/ParsingHelpers.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/unitility-core/src/main/java/com/synerset/unitility/unitsystem/util/ParsingHelpers.java b/unitility-core/src/main/java/com/synerset/unitility/unitsystem/util/ParsingHelpers.java index 7705ddd..3e85a78 100644 --- a/unitility-core/src/main/java/com/synerset/unitility/unitsystem/util/ParsingHelpers.java +++ b/unitility-core/src/main/java/com/synerset/unitility/unitsystem/util/ParsingHelpers.java @@ -11,13 +11,17 @@ private ParsingHelpers() { } /** - * Checks if the given input string contains any non-digit characters. + * Checks if the given input string contains any non-digit characters. Letter "e" and "-" + * are not counted as they may be part of very large or very small numbers ie: 1E-13. * * @param inputString The string to check * @return True if the string contains any non-digit characters, false otherwise */ public static boolean containsNonDigitChars(String inputString) { - for (char nextChar : inputString.toCharArray()) { + String preparedString = inputString.toLowerCase() + .replace("-", "") + .replace("e", ""); + for (char nextChar : preparedString.toCharArray()) { if (Character.isAlphabetic(nextChar)) { return true; }