Changes between Initial Version and Version 1 of Ticket #21982, comment 5
- Timestamp:
- 2022-04-01T05:22:08+02:00 (4 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #21982, comment 5
initial v1 7 7 } catch (NumberFormatException ex) { } 8 8 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)); 13 10 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)); 16 13 inches += 12 * feet; 17 14 return 0.0254 * inches; 15 } else { 16 return null; 18 17 } 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;34 18 } 35 19 }}} 20 21 Edit: I've greatly shortened the code above (still untested).


