-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Half-asian <[email protected]>
- Loading branch information
1 parent
e01f25b
commit 02d22c4
Showing
4 changed files
with
97 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include "Helpers.h" | ||
|
||
#include <charconv> | ||
|
||
int Helpers::StringToInt(const std::string& str, int defaultValue) | ||
{ | ||
int value; | ||
auto [p, ec] = std::from_chars(str.data(), str.data() + str.size(), value); | ||
|
||
if (ec != std::errc()) | ||
{ | ||
return defaultValue; | ||
} | ||
|
||
if (p[0] == 'M') | ||
{ | ||
value <<= 20; | ||
} | ||
|
||
if (p[0] == 'K') | ||
{ | ||
value <<= 10; | ||
} | ||
|
||
return value; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
|
||
class Helpers | ||
{ | ||
public: | ||
// Converts a value to integer with support for units such as megabytes | ||
static int StringToInt(const std::string& value, int defaultValue); | ||
}; |