From c99b24c16d1111a701d915832f24ac457aef697d Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Fri, 10 Jun 2016 14:06:06 +0600 Subject: COMMON: Add String::asUint64() Instead of all these atoull() I've added everywhere. --- backends/cloud/cloudmanager.cpp | 13 +------------ .../googledrive/googledrivelistdirectorybyidrequest.cpp | 13 +------------ backends/cloud/googledrive/googledrivestorage.cpp | 15 ++------------- backends/cloud/googledrive/googledriveuploadrequest.cpp | 15 ++------------- 4 files changed, 6 insertions(+), 50 deletions(-) (limited to 'backends') diff --git a/backends/cloud/cloudmanager.cpp b/backends/cloud/cloudmanager.cpp index 9456dd84a4..fed35a9f38 100644 --- a/backends/cloud/cloudmanager.cpp +++ b/backends/cloud/cloudmanager.cpp @@ -43,17 +43,6 @@ CloudManager::~CloudManager() { delete _activeStorage; } -namespace { -uint64 atoull(Common::String s) { - uint64 result = 0; - for (uint32 i = 0; i < s.size(); ++i) { - if (s[i] < '0' || s[i] > '9') break; - result = result * 10L + (s[i] - '0'); - } - return result; -} -} - Common::String CloudManager::getStorageConfigName(uint32 index) const { switch (index) { case kStorageNoneId: return ""; @@ -101,7 +90,7 @@ void CloudManager::init() { if (ConfMan.hasKey("storage_" + name + "_lastSync", "cloud")) config.lastSyncDate = ConfMan.get("storage_" + name + "_lastSync", "cloud"); if (ConfMan.hasKey("storage_" + name + "_usedBytes", "cloud")) - config.usedBytes = atoull(ConfMan.get("storage_" + name + "_usedBytes", "cloud")); + config.usedBytes = ConfMan.get("storage_" + name + "_usedBytes", "cloud").asUint64(); _storages.push_back(config); } diff --git a/backends/cloud/googledrive/googledrivelistdirectorybyidrequest.cpp b/backends/cloud/googledrive/googledrivelistdirectorybyidrequest.cpp index f9af363254..86494e8c13 100644 --- a/backends/cloud/googledrive/googledrivelistdirectorybyidrequest.cpp +++ b/backends/cloud/googledrive/googledrivelistdirectorybyidrequest.cpp @@ -67,17 +67,6 @@ void GoogleDriveListDirectoryByIdRequest::makeRequest(Common::String pageToken) _workingRequest = ConnMan.addRequest(request); } -namespace { -uint64 atoull(Common::String s) { - uint64 result = 0; - for (uint32 i = 0; i < s.size(); ++i) { - if (s[i] < '0' || s[i] > '9') break; - result = result * 10L + (s[i] - '0'); - } - return result; -} -} - void GoogleDriveListDirectoryByIdRequest::responseCallback(Networking::JsonResponse response) { _workingRequest = nullptr; if (_ignoreCallback) return; @@ -113,7 +102,7 @@ void GoogleDriveListDirectoryByIdRequest::responseCallback(Networking::JsonRespo bool isDirectory = (item.getVal("mimeType")->asString() == "application/vnd.google-apps.folder"); uint32 size = 0, timestamp = 0; if (item.contains("size") && item.getVal("size")->isString()) - size = atoull(item.getVal("size")->asString()); + size = item.getVal("size")->asString().asUint64(); if (item.contains("modifiedTime") && item.getVal("modifiedTime")->isString()) timestamp = ISO8601::convertToTimestamp(item.getVal("modifiedTime")->asString()); diff --git a/backends/cloud/googledrive/googledrivestorage.cpp b/backends/cloud/googledrive/googledrivestorage.cpp index 3196cbe041..91d8c819e7 100644 --- a/backends/cloud/googledrive/googledrivestorage.cpp +++ b/backends/cloud/googledrive/googledrivestorage.cpp @@ -137,17 +137,6 @@ Common::String GoogleDriveStorage::name() const { return "Google Drive"; } -namespace { -uint64 atoull(Common::String s) { - uint64 result = 0; - for (uint32 i = 0; i < s.size(); ++i) { - if (s[i] < '0' || s[i] > '9') break; - result = result * 10L + (s[i] - '0'); - } - return result; -} -} - void GoogleDriveStorage::infoInnerCallback(StorageInfoCallback outerCallback, Networking::JsonResponse response) { Common::JSONValue *json = response.value; if (!json) { @@ -175,8 +164,8 @@ void GoogleDriveStorage::infoInnerCallback(StorageInfoCallback outerCallback, Ne Common::JSONObject storageQuota = info.getVal("storageQuota")->asObject(); Common::String usage = storageQuota.getVal("usage")->asString(); Common::String limit = storageQuota.getVal("limit")->asString(); - quotaUsed = atoull(usage); - quotaAllocated = atoull(limit); + quotaUsed = usage.asUint64(); + quotaAllocated = limit.asUint64(); } CloudMan.setStorageUsername(kStorageGoogleDriveId, email); diff --git a/backends/cloud/googledrive/googledriveuploadrequest.cpp b/backends/cloud/googledrive/googledriveuploadrequest.cpp index f5636ef8ba..8dd8ffcc9a 100644 --- a/backends/cloud/googledrive/googledriveuploadrequest.cpp +++ b/backends/cloud/googledrive/googledriveuploadrequest.cpp @@ -207,17 +207,6 @@ void GoogleDriveUploadRequest::uploadNextPart() { _workingRequest = ConnMan.addRequest(request); } -namespace { -uint64 atoull(Common::String s) { - uint64 result = 0; - for (uint32 i = 0; i < s.size(); ++i) { - if (s[i] < '0' || s[i] > '9') break; - result = result * 10L + (s[i] - '0'); - } - return result; -} -} - bool GoogleDriveUploadRequest::handleHttp308(const Networking::NetworkReadStream *stream) { //308 Resume Incomplete, with Range: X-Y header if (!stream) return false; @@ -238,7 +227,7 @@ bool GoogleDriveUploadRequest::handleHttp308(const Networking::NetworkReadStream if (c == '\n' || c == '\r') break; result += c; } - _serverReceivedBytes = atoull(result) + 1; + _serverReceivedBytes = result.asUint64() + 1; uploadNextPart(); return true; } @@ -285,7 +274,7 @@ void GoogleDriveUploadRequest::partUploadedCallback(Networking::JsonResponse res bool isDirectory = (object.getVal("mimeType")->asString() == "application/vnd.google-apps.folder"); uint32 size = 0, timestamp = 0; if (object.contains("size") && object.getVal("size")->isString()) - size = atoull(object.getVal("size")->asString()); + size = object.getVal("size")->asString().asUint64(); if (object.contains("modifiedTime") && object.getVal("modifiedTime")->isString()) timestamp = ISO8601::convertToTimestamp(object.getVal("modifiedTime")->asString()); -- cgit v1.2.3