FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

phone numbers that start with one 0 get treated as int · Issue #49 · stleary/JSON-java · GitHub

phone numbers that start with one 0 get treated as int #49

Description

Hello,

Here in brazil we have phone numbers that start with 0800 and they get treated as ints thereby losing the first 0.

Tracked down the error to this bit of code in XML.java

    try {
        char initial = string.charAt(0);
        boolean negative = false;
        if (initial == '-') {
            initial = string.charAt(1);
            negative = true;
        }
        if (initial == '0' && string.charAt(negative ? 2 : 1) == '0') {
            return string;
        }
        if ((initial >= '0' && initial <= '9')) {
            if (string.indexOf('.') >= 0) {
                return Double.valueOf(string);
            } else if (string.indexOf('e') < 0 && string.indexOf('E') < 0) {
                Long myLong = new Long(string);
                if (myLong.longValue() == myLong.intValue()) {
                    return new Integer(myLong.intValue());
                } else {
                    return myLong;
                }
            }
        }
    }  catch (Exception ignore) {
    }

It seems to want to convert any value 0XNNNN... (where X isn't 0 and N is any digit) as an int.
Any particular reason for this?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL