[Scummvm-git-logs] scummvm master -> 18e6878311155f794594d908a34e1f02efb017a0
sev-
sev at scummvm.org
Sat Oct 17 20:35:02 UTC 2020
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
18e6878311 COMMON: Add String::asUint64Ext
Commit: 18e6878311155f794594d908a34e1f02efb017a0
https://github.com/scummvm/scummvm/commit/18e6878311155f794594d908a34e1f02efb017a0
Author: Vladimir Serbinenko (phcoder at google.com)
Date: 2020-10-17T22:34:58+02:00
Commit Message:
COMMON: Add String::asUint64Ext
This is the same as String::asUint64 but supports 0x and 0 prefixes
Changed paths:
common/str.cpp
common/str.h
diff --git a/common/str.cpp b/common/str.cpp
index a422e70384..4a15ccd957 100644
--- a/common/str.cpp
+++ b/common/str.cpp
@@ -441,6 +441,37 @@ uint64 String::asUint64() const {
return result;
}
+uint64 String::asUint64Ext() const {
+ uint64 result = 0;
+ uint64 base = 10;
+ uint32 skip = 0;
+
+ if (_size >= 3 && _str[0] == '0' && _str[1] == 'x') {
+ base = 16;
+ skip = 2;
+ } else if (_size >= 2 && _str[0] == '0') {
+ base = 8;
+ skip = 1;
+ } else {
+ base = 10;
+ skip = 0;
+ }
+ for (uint32 i = skip; i < _size; ++i) {
+ char digit = _str[i];
+ uint64 digitval = 17; // sentinel
+ if (digit >= '0' && digit <= '9')
+ digitval = digit - '0';
+ else if (digit >= 'a' && digit <= 'f')
+ digitval = digit - 'a' + 10;
+ else if (digit >= 'A' && digit <= 'F')
+ digitval = digit - 'A' + 10;
+ if (digitval > base)
+ break;
+ result = result * base + digitval;
+ }
+ return result;
+}
+
bool String::matchString(const char *pat, bool ignoreCase, bool pathMode) const {
return Common::matchString(c_str(), pat, ignoreCase, pathMode);
}
diff --git a/common/str.h b/common/str.h
index 33c8aa29b7..5371bcffda 100644
--- a/common/str.h
+++ b/common/str.h
@@ -190,6 +190,9 @@ public:
/** Return uint64 corrensponding to String's contents. */
uint64 asUint64() const;
+ /** Return uint64 corrensponding to String's contents. This variant recognizes 0 (oct) and 0x (hex) prefixes. */
+ uint64 asUint64Ext() const;
+
/**
* Simple DOS-style pattern matching function (understands * and ? like used in DOS).
* Taken from exult/files/listfiles.cc
More information about the Scummvm-git-logs
mailing list