JsonElementContainer implements ElementContainer { public static String stripLeadingZeroes(String value) { if (value.length()>1) { boolean negative=value.charAt(0)=='-'; int i=negative?1:0; while (i<value.length()-1 && value.charAt(i)=='0' && Character.isDigit(value.charAt(i+1))) { i++; } if (i>(negative?1:0)) { return (negative?"-":"")+value.substring(i); } } return value; } JsonElementContainer(String name, boolean xmlArrayContainer, boolean repeatedElement, boolean skipArrayElementContainers, String attributePrefix, String mixedContentLabel, XSTypeDefinition typeDefinition); @Override void setNull(); @Override void setAttribute(String name, String value, XSSimpleTypeDefinition attTypeDefinition); @Override void characters(char[] ch, int start, int length); void setContent(String content); void addContent(JsonElementContainer content); static String stripLeadingZeroes(String value); Object getContent(); @Override String toString(); String getName(); boolean isXmlArrayContainer(); boolean isRepeatedElement(); ScalarType getType(); void setType(ScalarType type); public String stringContent; static final CharSequenceTranslator ESCAPE_JSON; }
@Test public void testStripLeadingZeroes() { for (int i=1; i<12;i++) { testStripLeadingZeroes(""+i,""+i); testStripLeadingZeroes(""+i,"0"+i); testStripLeadingZeroes("0.0"+i,"0.0"+i); testStripLeadingZeroes("0.0"+i,"000.0"+i); testStripLeadingZeroes("-"+i,"-"+i); testStripLeadingZeroes("-"+i,"-0"+i); testStripLeadingZeroes("-0.0"+i,"-0.0"+i); testStripLeadingZeroes("-0.0"+i,"-000.0"+i); } testStripLeadingZeroes("0","0"); testStripLeadingZeroes("0","00"); testStripLeadingZeroes("0","000"); }