77 lines
1.7 KiB
C++
77 lines
1.7 KiB
C++
#pragma once
|
|
|
|
#include <QtEndian>
|
|
#include <QtGlobal>
|
|
|
|
#include <QCoreApplication>
|
|
|
|
#include <algorithm>
|
|
#include <array>
|
|
#include <filesystem>
|
|
#include <fstream>
|
|
#include <ios>
|
|
#include <iostream>
|
|
#include <istream>
|
|
#include <iterator>
|
|
#include <stdexcept>
|
|
#include <string>
|
|
#include <utility>
|
|
|
|
static inline QString trMain(char const *sourceText,
|
|
char const *disambiguation = nullptr,
|
|
int n = -1) {
|
|
return QCoreApplication::translate("main", sourceText, disambiguation, n);
|
|
}
|
|
|
|
template<typename T>
|
|
static inline T readLE(std::istream &st) {
|
|
std::array<char, sizeof(T)> b;
|
|
st.read(b.data(), b.size());
|
|
return qFromLittleEndian<T>(b.data());
|
|
}
|
|
|
|
template<typename T>
|
|
static inline T readBE(std::istream &st) {
|
|
std::array<char, sizeof(T)> b;
|
|
st.read(b.data(), b.size());
|
|
return qFromBigEndian<T>(b.data());
|
|
}
|
|
|
|
template<std::size_t N>
|
|
static inline std::array<char, N> readBytes(std::istream &st) {
|
|
std::array<char, N> b;
|
|
st.read(b.data(), b.size());
|
|
return std::move(b);
|
|
}
|
|
|
|
template<typename It>
|
|
static inline std::string escapeText(It begin, It end) {
|
|
std::stringstream out;
|
|
out << std::hex << std::uppercase;
|
|
for(auto it = begin; it != end; ++it) {
|
|
unsigned char c = *it;
|
|
switch(c) {
|
|
case '"': out << "\\\""; break;
|
|
case '\0': out << "\\0"; break;
|
|
case '\\': out << "\\\\"; break;
|
|
case '\a': out << "\\a"; break;
|
|
case '\b': out << "\\b"; break;
|
|
case '\f': out << "\\f"; break;
|
|
case '\n': out << "\\n"; break;
|
|
case '\r': out << "\\r"; break;
|
|
case '\t': out << "\\t"; break;
|
|
case '\v': out << "\\v"; break;
|
|
default:
|
|
if(c >= ' ' && c <= '~') {
|
|
out << c;
|
|
} else {
|
|
out << "\\x" << int(c);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
return out.str();
|
|
}
|
|
|
|
// EOF
|