47 {
48
49 // public methods ------------------------------------------------------
50
51 /**
52 * Returns an instance of VersionInfo with the argument version.
53 * @param version version String in the format of "major.minor.milli.micro"
54 * or "major.minor.milli" or "major.minor" or "major",
55 * where major, minor, milli, micro are non-negative numbers
56 * {@literal <=} 255. If the trailing version numbers are
57 * not specified they are taken as 0s. E.g. Version "3.1" is
58 * equivalent to "3.1.0.0".
59 * @return an instance of VersionInfo with the argument version.
60 * @exception throws an IllegalArgumentException when the argument version
61 * is not in the right format
62 * @stable ICU 2.6
63 */
64 public static VersionInfo getInstance(String version)
65 {
66 int length = version.length();
67 int array[] = {0, 0, 0, 0};
68 int count = 0;
69 int index = 0;
70
71 while (count < 4 && index < length) {
72 char c = version.charAt(index);
73 if (c == '.') {
74 count ++;
75 }
76 else {
77 c -= '0';
78 if (c < 0 || c > 9) {
79 throw new IllegalArgumentException(INVALID_VERSION_NUMBER_);
80 }
81 array[count] *= 10;
82 array[count] += c;
83 }
84 index ++;
85 }
86 if (index != length) {
87 throw new IllegalArgumentException(
|
47 {
48
49 // public methods ------------------------------------------------------
50
51 /**
52 * Returns an instance of VersionInfo with the argument version.
53 * @param version version String in the format of "major.minor.milli.micro"
54 * or "major.minor.milli" or "major.minor" or "major",
55 * where major, minor, milli, micro are non-negative numbers
56 * {@literal <=} 255. If the trailing version numbers are
57 * not specified they are taken as 0s. E.g. Version "3.1" is
58 * equivalent to "3.1.0.0".
59 * @return an instance of VersionInfo with the argument version.
60 * @exception throws an IllegalArgumentException when the argument version
61 * is not in the right format
62 * @stable ICU 2.6
63 */
64 public static VersionInfo getInstance(String version)
65 {
66 int length = version.length();
67 int[] array = {0, 0, 0, 0};
68 int count = 0;
69 int index = 0;
70
71 while (count < 4 && index < length) {
72 char c = version.charAt(index);
73 if (c == '.') {
74 count ++;
75 }
76 else {
77 c -= '0';
78 if (c < 0 || c > 9) {
79 throw new IllegalArgumentException(INVALID_VERSION_NUMBER_);
80 }
81 array[count] *= 10;
82 array[count] += c;
83 }
84 index ++;
85 }
86 if (index != length) {
87 throw new IllegalArgumentException(
|