Add util functions

This commit is contained in:
2020-12-04 00:06:11 +01:00
parent 8011c094c7
commit 01fd1c7aaf
2 changed files with 25 additions and 1 deletions

View File

@@ -92,6 +92,20 @@ namespace openVulkanoCpp
return log;
}
static constexpr int64_t OctToInt(std::string_view string)
{
int64_t result = 0;
for(int i = string.length() - 1; i >= 0; i--)
{
char c = string[i];
if (c == 0) break;
if (c == ' ') continue;
if (c < '0' || c > '7') return -1;
result = result * 8 + c - '0';
}
return result;
}
static bool IsLittleEndian()
{ //TODO update with cpp20
const int value { 0x01 };
@@ -100,5 +114,15 @@ namespace openVulkanoCpp
return (*least_significant_address == 0x01);
}
static constexpr bool StartsWith(std::string_view str, std::string_view prefix)
{
return str.size() >= prefix.size() && 0 == str.compare(0, prefix.size(), prefix);
}
static constexpr bool EndsWith(std::string_view str, std::string_view suffix)
{
return str.size() >= suffix.size() && 0 == str.compare(str.size()-suffix.size(), suffix.size(), suffix);
}
};
}