Compare commits
12 Commits
Author | SHA1 | Date |
---|---|---|
Deukhoofd | 7da2e27d22 | |
Deukhoofd | 3df014f332 | |
Deukhoofd | 0d627d3e7b | |
Deukhoofd | 003e33c05a | |
Deukhoofd | 5311df51ad | |
Deukhoofd | f95ee90a20 | |
Deukhoofd | d7beb77f1d | |
Deukhoofd | 14a8709631 | |
Deukhoofd | f2a4352f44 | |
Deukhoofd | ee85947c4c | |
Deukhoofd | a56ccf68ec | |
Deukhoofd | b0817fcad2 |
20
.drone.yml
20
.drone.yml
|
@ -9,21 +9,27 @@ steps:
|
|||
CC: /usr/bin/clang
|
||||
CXX: /usr/bin/clang++
|
||||
commands:
|
||||
- cmake -DCMAKE_BUILD_TYPE=Release . -B build-release
|
||||
- cmake -GNinja -DCMAKE_BUILD_TYPE=Release . -B build-release
|
||||
- cmake --build build-release --target all -- -j 4
|
||||
- name: build-release-windows
|
||||
image: deukhoofd/windowsbuilder
|
||||
environment:
|
||||
CHOST: x86_64-w64-mingw32
|
||||
AR: x86_64-w64-mingw32-ar
|
||||
AS: x86_64-w64-mingw32-as
|
||||
RANLIB: x86_64-w64-mingw32-ranlib
|
||||
CC: x86_64-w64-mingw32-gcc
|
||||
CXX: x86_64-w64-mingw32-g++
|
||||
STRIP: x86_64-w64-mingw32-strip
|
||||
RC: x86_64-w64-mingw32-windres
|
||||
commands:
|
||||
- update-alternatives --set i686-w64-mingw32-gcc /usr/bin/i686-w64-mingw32-gcc-posix
|
||||
- update-alternatives --set i686-w64-mingw32-g++ /usr/bin/i686-w64-mingw32-g++-posix
|
||||
- update-alternatives --set x86_64-w64-mingw32-gcc /usr/bin/x86_64-w64-mingw32-gcc-posix
|
||||
- update-alternatives --set x86_64-w64-mingw32-g++ /usr/bin/x86_64-w64-mingw32-g++-posix
|
||||
- cmake -DCMAKE_BUILD_TYPE=Release . -B build-release-windows -D CMAKE_C_COMPILER=/usr/bin/x86_64-w64-mingw32-gcc -D CMAKE_CXX_COMPILER=x86_64-w64-mingw32-g++
|
||||
- cmake -GNinja -DCMAKE_BUILD_TYPE=Release . -B build-release-windows -D CMAKE_C_COMPILER=/usr/bin/x86_64-w64-mingw32-gcc -D CMAKE_CXX_COMPILER=x86_64-w64-mingw32-g++
|
||||
- cmake --build build-release-windows --target all -- -j 4
|
||||
- name: gitea_release
|
||||
image: plugins/gitea-release
|
||||
settings:
|
||||
api_key: 684b59c5281894a312cfb5f7c158a7720791eff1
|
||||
api_key:
|
||||
from_secret: gitea_token
|
||||
base_url: https://git.p-epsilon.com/
|
||||
files:
|
||||
- build-release/LangBuilder
|
||||
|
|
|
@ -5,8 +5,9 @@ project(LangBuilder)
|
|||
add_compile_options(-Wall -Wextra -Werror)
|
||||
# We like new stuff, so set the c++ standard to c++20.
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(BUILD_SHARED_LIBS OFF)
|
||||
|
||||
file(GLOB_RECURSE SRC_FILES "src/*.cpp" "src/*.hpp")
|
||||
|
||||
add_executable(LangBuilder ${SRC_FILES})
|
||||
target_link_libraries(LangBuilder -static-libgcc -static-libstdc++ -Wl,-Bstatic -lstdc++ -lpthread)
|
||||
target_link_libraries(LangBuilder -static -static-libgcc -static-libstdc++ -Wl,-Bstatic -lstdc++ -lpthread)
|
|
@ -78,37 +78,44 @@ void LocalizationData::WriteToFile(const std::filesystem::path& path) {
|
|||
tempFilesPositions[file.first] = p1;
|
||||
}
|
||||
outFile << "ENDDATA" << std::endl;
|
||||
|
||||
size_t numberGlobal = 0;
|
||||
// actual localization
|
||||
for (const auto& file : _globalFiles) {
|
||||
auto pos = outFile.tellp();
|
||||
for (const auto& kv : file.second.GetMap()) {
|
||||
outFile << kv.first << "|" << kv.second << std::endl;
|
||||
numberGlobal++;
|
||||
}
|
||||
auto end = outFile.tellp();
|
||||
auto length = end - pos;
|
||||
auto data = globalFilesPositions[file.first];
|
||||
outFile.seekp(data);
|
||||
outFile << std::setfill ('0') << std::setw(4) << std::hex << pos;
|
||||
outFile << std::setfill('0') << std::setw(4) << std::hex << pos;
|
||||
outFile << "~";
|
||||
outFile << std::setfill ('0') << std::setw(4) << std::hex << length;
|
||||
outFile << std::setfill('0') << std::setw(4) << std::hex << length;
|
||||
outFile.seekp(end);
|
||||
}
|
||||
|
||||
size_t numberTemp = 0;
|
||||
for (const auto& file : _tempFiles) {
|
||||
auto pos = outFile.tellp();
|
||||
for (const auto& kv : file.second.GetMap()) {
|
||||
outFile << kv.first << "|" << kv.second << std::endl;
|
||||
numberTemp++;
|
||||
}
|
||||
auto end = outFile.tellp();
|
||||
auto length = end - pos;
|
||||
auto data = tempFilesPositions[file.first];
|
||||
outFile.seekp(data);
|
||||
outFile << std::setfill ('0') << std::setw(4) << std::hex << pos;
|
||||
outFile << std::setfill('0') << std::setw(4) << std::hex << pos;
|
||||
outFile << "~";
|
||||
outFile << std::setfill ('0') << std::setw(4) << std::hex << length;
|
||||
outFile << std::setfill('0') << std::setw(4) << std::hex << length;
|
||||
outFile.seekp(end);
|
||||
}
|
||||
|
||||
outFile.close();
|
||||
|
||||
std::cout << "Wrote language file to " << path << std::endl;
|
||||
std::cout << "Wrote language file to " << path << ". Wrote " << numberGlobal << " global keys and " << numberTemp
|
||||
<< " temp keys." << std::endl;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,20 @@
|
|||
#include "LocalizationFile.hpp"
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <regex>
|
||||
|
||||
const std::regex keyChecker = std::regex("[^a-z0-9_]+");
|
||||
|
||||
static bool IsKeyValid(const std::string_view & key){
|
||||
if (std::regex_search(key.begin(), key.end(), keyChecker)){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
const char PossibleSeparators[] = {
|
||||
',', ';', '|', '\t', ':'
|
||||
};
|
||||
|
||||
void LocalizationFile::LoadFile(const std::filesystem::path& path) {
|
||||
if (!std::filesystem::exists(path)) {
|
||||
|
@ -21,9 +35,11 @@ void LocalizationFile::LoadFile(const std::filesystem::path& path) {
|
|||
while (std::getline(file, line)) {
|
||||
if (firstLine) {
|
||||
firstLine = false;
|
||||
if (line.substr(0, 4) == "sep=") {
|
||||
sep = line[4];
|
||||
continue;
|
||||
for (auto& s :PossibleSeparators) {
|
||||
if (line.find(s) != std::string::npos){
|
||||
sep = s;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
std::string key;
|
||||
|
@ -31,6 +47,13 @@ void LocalizationFile::LoadFile(const std::filesystem::path& path) {
|
|||
std::stringstream linestream(line);
|
||||
std::getline(linestream, key, sep);
|
||||
std::getline(linestream, value, sep);
|
||||
if (key.empty())
|
||||
continue;
|
||||
if (key == "key" && value == "value")
|
||||
continue;
|
||||
if (!IsKeyValid(key)){
|
||||
std::cout << "Key not valid: '" << key << "'. Skipping key." << std::endl;
|
||||
}
|
||||
_map[key] = value;
|
||||
}
|
||||
file.close();
|
||||
|
|
Loading…
Reference in New Issue