- Array<String> version;
- version = String_convert::split_arr (str, '.');
-
- major_i_ = version[0].value_i ();
- minor_i_ = version[1].value_i ();
- patch_i_ = 0;
- if (version.size () >= 3)
- patch_i_ = version[2].value_i ();
-
- if (version.size () >= 4)
- extra_patch_str_ = version[3];
+ major_ = -1;
+ minor_ = 0;
+ patch_ = 0;
+
+ vector<string> version;
+ const char *digits = "0123456789";
+ version = string_split (str, '.');
+
+ switch (version.size ()) {
+ case 4:
+ extra_patch_string_ = version[3];
+ if (version[2].empty ())
+ return;
+ case 3:
+ if (version[2].find_first_not_of (digits) != string::npos
+ || version[1].empty ())
+ return;
+ patch_ = String_convert::dec2int (version[2]);
+ case 2:
+ if (version[1].find_first_not_of (digits) != string::npos
+ || version[1].empty () || version[0].empty ())
+ return;
+ minor_ = String_convert::dec2int (version[1]);
+ if (version[0].find_first_not_of (digits) != string::npos)
+ return;
+ major_ = String_convert::dec2int (version[0]);
+ }