Changes between Initial Version and Version 1 of Ticket #21982, comment 5


Ignore:
Timestamp:
2022-04-01T05:22:08+02:00 (4 years ago)
Author:
happy5214

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #21982, comment 5

    initial v1  
    77        } catch (NumberFormatException ex) { }
    88
    9         int feet, inches;
    10         List<String> matchList;
    11 
    12         matchList = Utils.getMatches(Pattern.compile("(\\d+)\'(\\d+)\"").matcher(source));
     9        List<String> matchList = Utils.getMatches(Pattern.compile("^(?:((?:\\d*\\.)?\\d+)\')?(?:((?:\\d*\\.)?\\d+)\")?$").matcher(source));
    1310        if (matchList != null) {
    14             feet = matchList.get(1);
    15             inches = matchList.get(2);
     11            double feet = matchList.get(1) == null ? 0.0 : Double.parseDouble(matchList.get(1));
     12            double inches = matchList.get(2) == null ? 0.0 : Double.parseDouble(matchList.get(2));
    1613            inches += 12 * feet;
    1714            return 0.0254 * inches;
     15        } else {
     16            return null;
    1817        }
    19 
    20         matchList = Utils.getMatches(Pattern.compile("(\\d+)\'").matcher(source));
    21         if (matchList != null) {
    22             feet = matchList.get(1);
    23             inches = 12 * feet;
    24             return 0.0254 * inches;
    25         }
    26 
    27         matchList = Utils.getMatches(Pattern.compile("(\\d+)\"").matcher(source));
    28         if (matchList != null) {
    29             inches = matchList.get(1);
    30             return 0.0254 * inches;
    31         }
    32 
    33         return null;
    3418    }
    3519}}}
     20
     21Edit: I've greatly shortened the code above (still untested).