@Test public void parseNumbers() { String numbers = "10.0 -10.0-1f"; SVGParser.NumberParse numberParse = SVGParser.parseNumbers(numbers); assertThat(numberParse.getNumber(0), is(10.0f)); assertThat(numberParse.getNumber(1), is(-10.0f)); assertThat(numberParse.getNumber(2), is(-1.0f)); assertThat(numberParse.getNextCmd(), is(numbers.length())); }
protected static NumberParse parseNumbers(String s) { int n = s.length(); int p = 0; ArrayList<Float> numbers = new ArrayList<>(); boolean skipChar = false; for (int i = 1; i < n; i++) { if (skipChar) { skipChar = false; continue; } char c = s.charAt(i); switch (c) { case 'M': case 'm': case 'Z': case 'z': case 'L': case 'l': case 'H': case 'h': case 'V': case 'v': case 'C': case 'c': case 'S': case 's': case 'Q': case 'q': case 'T': case 't': case 'a': case 'A': case ')': { String str = s.substring(p, i); if (str.trim().length() > 0) { Float f = Float.parseFloat(str); numbers.add(f); } p = i; return new NumberParse(numbers, p); } case '\n': case '\t': case ' ': case ',': case '-': { String str = s.substring(p, i); if (str.trim().length() > 0) { Float f = Float.parseFloat(str); numbers.add(f); if (c == '-') { p = i; } else { p = i + 1; skipChar = true; } } else { p++; } break; } } } String last = s.substring(p); if (last.length() > 0) { try { numbers.add(Float.parseFloat(last)); } catch (NumberFormatException nfe) { } p = s.length(); } return new NumberParse(numbers, p); }
SVGParser { protected static NumberParse parseNumbers(String s) { int n = s.length(); int p = 0; ArrayList<Float> numbers = new ArrayList<>(); boolean skipChar = false; for (int i = 1; i < n; i++) { if (skipChar) { skipChar = false; continue; } char c = s.charAt(i); switch (c) { case 'M': case 'm': case 'Z': case 'z': case 'L': case 'l': case 'H': case 'h': case 'V': case 'v': case 'C': case 'c': case 'S': case 's': case 'Q': case 'q': case 'T': case 't': case 'a': case 'A': case ')': { String str = s.substring(p, i); if (str.trim().length() > 0) { Float f = Float.parseFloat(str); numbers.add(f); } p = i; return new NumberParse(numbers, p); } case '\n': case '\t': case ' ': case ',': case '-': { String str = s.substring(p, i); if (str.trim().length() > 0) { Float f = Float.parseFloat(str); numbers.add(f); if (c == '-') { p = i; } else { p = i + 1; skipChar = true; } } else { p++; } break; } } } String last = s.substring(p); if (last.length() > 0) { try { numbers.add(Float.parseFloat(last)); } catch (NumberFormatException nfe) { } p = s.length(); } return new NumberParse(numbers, p); } }
SVGParser { protected static NumberParse parseNumbers(String s) { int n = s.length(); int p = 0; ArrayList<Float> numbers = new ArrayList<>(); boolean skipChar = false; for (int i = 1; i < n; i++) { if (skipChar) { skipChar = false; continue; } char c = s.charAt(i); switch (c) { case 'M': case 'm': case 'Z': case 'z': case 'L': case 'l': case 'H': case 'h': case 'V': case 'v': case 'C': case 'c': case 'S': case 's': case 'Q': case 'q': case 'T': case 't': case 'a': case 'A': case ')': { String str = s.substring(p, i); if (str.trim().length() > 0) { Float f = Float.parseFloat(str); numbers.add(f); } p = i; return new NumberParse(numbers, p); } case '\n': case '\t': case ' ': case ',': case '-': { String str = s.substring(p, i); if (str.trim().length() > 0) { Float f = Float.parseFloat(str); numbers.add(f); if (c == '-') { p = i; } else { p = i + 1; skipChar = true; } } else { p++; } break; } } } String last = s.substring(p); if (last.length() > 0) { try { numbers.add(Float.parseFloat(last)); } catch (NumberFormatException nfe) { } p = s.length(); } return new NumberParse(numbers, p); }  }
SVGParser { protected static NumberParse parseNumbers(String s) { int n = s.length(); int p = 0; ArrayList<Float> numbers = new ArrayList<>(); boolean skipChar = false; for (int i = 1; i < n; i++) { if (skipChar) { skipChar = false; continue; } char c = s.charAt(i); switch (c) { case 'M': case 'm': case 'Z': case 'z': case 'L': case 'l': case 'H': case 'h': case 'V': case 'v': case 'C': case 'c': case 'S': case 's': case 'Q': case 'q': case 'T': case 't': case 'a': case 'A': case ')': { String str = s.substring(p, i); if (str.trim().length() > 0) { Float f = Float.parseFloat(str); numbers.add(f); } p = i; return new NumberParse(numbers, p); } case '\n': case '\t': case ' ': case ',': case '-': { String str = s.substring(p, i); if (str.trim().length() > 0) { Float f = Float.parseFloat(str); numbers.add(f); if (c == '-') { p = i; } else { p = i + 1; skipChar = true; } } else { p++; } break; } } } String last = s.substring(p); if (last.length() > 0) { try { numbers.add(Float.parseFloat(last)); } catch (NumberFormatException nfe) { } p = s.length(); } return new NumberParse(numbers, p); }  static SVG getSVGFromInputStream(InputStream svgData); static SVG getSVGFromInputStream(InputStream svgData, int targetWidth, int targetHeight); static SVG getSVGFromResource(Resources resources, int resId); static SVG getSVGFromAsset(AssetManager assetMngr, String svgPath); static SVG getSVGFromInputStream(InputStream svgData, int searchColor, int replaceColor,
                                            int targetWidth, int targetHeight); static SVG getSVGFromString(String svgData, int searchColor, int replaceColor); static SVG getSVGFromResource(Resources resources, int resId, int searchColor, int replaceColor); static SVG getSVGFromAsset(AssetManager assetMngr, String svgPath, int searchColor, int replaceColor); static Path parsePath(String pathString); }
SVGParser { protected static NumberParse parseNumbers(String s) { int n = s.length(); int p = 0; ArrayList<Float> numbers = new ArrayList<>(); boolean skipChar = false; for (int i = 1; i < n; i++) { if (skipChar) { skipChar = false; continue; } char c = s.charAt(i); switch (c) { case 'M': case 'm': case 'Z': case 'z': case 'L': case 'l': case 'H': case 'h': case 'V': case 'v': case 'C': case 'c': case 'S': case 's': case 'Q': case 'q': case 'T': case 't': case 'a': case 'A': case ')': { String str = s.substring(p, i); if (str.trim().length() > 0) { Float f = Float.parseFloat(str); numbers.add(f); } p = i; return new NumberParse(numbers, p); } case '\n': case '\t': case ' ': case ',': case '-': { String str = s.substring(p, i); if (str.trim().length() > 0) { Float f = Float.parseFloat(str); numbers.add(f); if (c == '-') { p = i; } else { p = i + 1; skipChar = true; } } else { p++; } break; } } } String last = s.substring(p); if (last.length() > 0) { try { numbers.add(Float.parseFloat(last)); } catch (NumberFormatException nfe) { } p = s.length(); } return new NumberParse(numbers, p); }  static SVG getSVGFromInputStream(InputStream svgData); static SVG getSVGFromInputStream(InputStream svgData, int targetWidth, int targetHeight); static SVG getSVGFromResource(Resources resources, int resId); static SVG getSVGFromAsset(AssetManager assetMngr, String svgPath); static SVG getSVGFromInputStream(InputStream svgData, int searchColor, int replaceColor,
                                            int targetWidth, int targetHeight); static SVG getSVGFromString(String svgData, int searchColor, int replaceColor); static SVG getSVGFromResource(Resources resources, int resId, int searchColor, int replaceColor); static SVG getSVGFromAsset(AssetManager assetMngr, String svgPath, int searchColor, int replaceColor); static Path parsePath(String pathString);  }