14 if (sPart.empty())
return false;
17 for (
char c : sPart) {
18 if (c <
'0' || c >
'9')
return false;
23 long long llVal = std::stoll(sPart);
24 if (llVal < 0 || llVal > 2147483647LL)
return false;
25 iVal =
static_cast<int>(llVal);
34 if (sInput.
IsEmpty())
return false;
36 if (s.empty() || s.front() ==
'.' || s.back() ==
'.')
return false;
39 std::stringstream ss(s);
41 while (std::getline(ss, item,
'.')) {
42 if (item.empty())
return false;
43 vecParts.push_back(item);
47 return (vecParts.size() >= 2 && vecParts.size() <= 4);
50 static bool TryParseInternal(
const String& sInput,
int& iMajor,
int& iMinor,
int& iBuild,
int& iRevision,
int& iCount) {
52 std::vector<std::string> vecParts;
56 iCount =
static_cast<int>(vecParts.size());
57 int arrVals[4] = { 0, 0, 0, 0 };
58 for (
size_t i = 0; i < vecParts.size(); ++i) {
63 iBuild = (iCount >= 3) ? arrVals[2] : 0;
64 iRevision = (iCount == 4) ? arrVals[3] : 0;
69 : m_iMajor(iMajor), m_iMinor(iMinor), m_iBuild(iBuild), m_iRevision(iRevision) { }
72 : m_iMajor(iMajor), m_iMinor(iMinor), m_iBuild(iBuild), m_iRevision(0) { }
75 : m_iMajor(iMajor), m_iMinor(iMinor), m_iBuild(0), m_iRevision(0) { }
78 : m_iMajor(0), m_iMinor(0), m_iBuild(0), m_iRevision(0) { }
98 ss << m_iMajor <<
"." << m_iMinor <<
"." << m_iBuild <<
"." << m_iRevision;
99 return String(ss.str().c_str());
114 int iMajor = 0, iMinor = 0, iBuild = 0, iRevision = 0, iCount = 0;
118 if (iCount == 2) vResult =
Version(iMajor, iMinor);
119 else if (iCount == 3) vResult =
Version(iMajor, iMinor, iBuild);
120 else vResult =
Version(iMajor, iMinor, iBuild, iRevision);
125 return m_iMajor == vOther.m_iMajor &&
126 m_iMinor == vOther.m_iMinor &&
127 m_iBuild == vOther.m_iBuild &&
128 m_iRevision == vOther.m_iRevision;
132 return !(*
this == other);
Defines the exception thrown when an invalid argument is provided to a method.
Represents the version number of an assembly, operating system, or application component.
ArgumentException(const String &sMessage)
Initializes a new instance of the ArgumentException class with a specified error message.
Represents text as a sequence of UTF-8 code units with culture-invariant operations.
String()
Initializes a new instance of the String class to an empty string.
const char * GetRawString() const
int GetMajor() const
Gets the value of the major component of the version number.
bool operator==(const Version &vOther) const
Determines whether two Version instances are equal.
Version(int iMajor, int iMinor, int iBuild, int iRevision)
Initializes a new instance of the Version class using specified major, minor, build,...
int GetMinor() const
Gets the value of the minor component of the version number.
static bool TryParse(const String &sInput, Version &vResult)
Tries to convert the string representation of a version number to an equivalent Version object.
Version()
Initializes a new instance of the Version class to 0.0.0.0.
int GetRevision() const
Gets the value of the revision component of the version number.
static Version Parse(const String &sInput)
Converts the string representation of a version number to an equivalent Version object.
int GetBuild() const
Gets the value of the build component of the version number.
bool operator!=(const Version &vOther) const
Determines whether two Version instances are not equal.
String ToString() const
Converts the value of the current Version object to its equivalent String representation.
static bool TryParseInternal(const String &sInput, int &iMajor, int &iMinor, int &iBuild, int &iRevision, int &iCount)
static bool SplitVersionParts(const String &sInput, std::vector< std::string > &vecParts)
static bool ParseComponent(const std::string &sPart, int &iVal)