X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=altoslib%2FAltosParse.java;h=fbd049ae7a3da093c89de7ea5345546a4d3b8bf5;hb=2a4d741872449b5332f28e018fa3acc53ed7d891;hp=e938a177e6b3967926e3f5ffd756cc1200653974;hpb=e2b458a448106ba1ab207f0ea6824b56927d8547;p=fw%2Faltos diff --git a/altoslib/AltosParse.java b/altoslib/AltosParse.java index e938a177..fbd049ae 100644 --- a/altoslib/AltosParse.java +++ b/altoslib/AltosParse.java @@ -15,8 +15,9 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.AltosLib; +package org.altusmetrum.altoslib_11; +import java.util.*; import java.text.*; public class AltosParse { @@ -25,6 +26,14 @@ public class AltosParse { } public static int parse_int(String v) throws ParseException { + try { + return (int) AltosLib.fromdec(v); + } catch (NumberFormatException e) { + throw new ParseException("error parsing int " + v, 0); + } + } + + public static long parse_long(String v) throws ParseException { try { return AltosLib.fromdec(v); } catch (NumberFormatException e) { @@ -40,14 +49,34 @@ public class AltosParse { } } - public static double parse_double(String v) throws ParseException { + static NumberFormat nf_locale = NumberFormat.getInstance(); + + static NumberFormat nf_net = NumberFormat.getInstance(Locale.ROOT); + + public static double parse_double_locale(String str) throws ParseException { try { - return Double.parseDouble(v); - } catch (NumberFormatException e) { - throw new ParseException("error parsing double " + v, 0); + return nf_locale.parse(str.trim()).doubleValue(); + } catch (ParseException pe) { + throw new ParseException("error parsing double " + str, 0); } } + public static String format_double_locale(double number) { + return nf_locale.format(number); + } + + public static double parse_double_net(String str) throws ParseException { + try { + return nf_net.parse(str.trim()).doubleValue(); + } catch (ParseException pe) { + throw new ParseException("error parsing double " + str, 0); + } + } + + public static String format_double_net(double number) { + return nf_net.format(number); + } + public static double parse_coord(String coord) throws ParseException { String[] dsf = coord.split("\\D+");