Files
ppsspp/Common/Data/Text/Parsers.h

77 lines
1.7 KiB
C
Raw Permalink Normal View History

2013-11-26 13:56:22 +01:00
#pragma once
#include <string>
#include <sstream>
#include <cstdint>
2013-11-28 12:35:58 +01:00
2013-11-27 03:01:56 +10:00
#undef major
#undef minor
2013-11-26 13:56:22 +01:00
// Parses version strings of the format "Major.Minor.Sub" and lets you interact with them conveniently.
struct Version {
Version() : major(0), minor(0), sub(0) {}
2013-11-27 03:01:56 +10:00
Version(const std::string &str) {
2013-11-26 13:56:22 +01:00
if (!ParseVersionString(str)) {
major = -1;
minor = -1;
sub = -1;
}
}
int major;
int minor;
int sub;
bool IsValid() const {
return sub >= 0 && minor >= 0 && major >= 0;
}
bool operator == (const Version &other) const {
return major == other.major && minor == other.minor && sub == other.sub;
}
bool operator != (const Version &other) const {
return !(*this == other);
}
bool operator <(const Version &other) const {
if (major < other.major) return true;
if (major > other.major) return false;
if (minor < other.minor) return true;
if (minor > other.minor) return false;
if (sub < other.sub) return true;
if (sub > other.sub) return false;
return false;
}
bool operator >=(const Version &other) const {
return !(*this < other);
}
std::string ToString() const;
int ToInteger() const;
2013-11-26 13:56:22 +01:00
private:
bool ParseVersionString(std::string str);
};
2013-11-28 12:35:58 +01:00
bool ParseMacAddress(std::string str, uint8_t macAddr[6]);
bool TryParse(const std::string &str, bool *const output);
bool TryParse(const std::string &str, uint32_t *const output);
bool TryParse(const std::string &str, uint64_t *const output);
template <typename N>
static bool TryParse(const std::string &str, N *const output) {
std::istringstream iss(str);
N tmp = 0;
if (iss >> tmp) {
*output = tmp;
return true;
} else
return false;
}
2021-07-26 22:11:07 +02:00
2021-09-18 15:10:31 +02:00
void NiceSizeFormat(uint64_t size, char *out, size_t bufSize);
std::string NiceSizeFormat(uint64_t size);