From 42336c560a751297dfe5bb83f95b03a22ef2ac80 Mon Sep 17 00:00:00 2001 From: Milan Suman <> Date: Mon, 18 Jul 2022 12:13:10 +0530 Subject: [PATCH] Birthed an abomination, what the fuck --- scripts/test.sh | 1 + src/lib/java_string.cpp | 22 ++++++++++--- src/lib/java_string.h++ | 2 +- src/test/java_string.cpp | 70 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 90 insertions(+), 5 deletions(-) create mode 100644 src/test/java_string.cpp diff --git a/scripts/test.sh b/scripts/test.sh index bbfde42..5248526 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -39,6 +39,7 @@ echo "Building tests..." COMPILE_COMMANDS=( "$CXX_WITH_FLAGS src/test/nbt_helpers.cpp -Lbin/lib -l:nbt.so -o bin/test/nbt_helpers" "$CXX_WITH_FLAGS src/test/cli_argument_parser.cpp -Lbin/lib -l:cli.so -o bin/test/cli_argument_parser" + "$CXX_WITH_FLAGS src/test/java_string.cpp -Idependencies/tiny-utf8-4.4.3/include -Lbin/lib -l:java_string.so -o bin/test/java_string" ) for command in ${!COMPILE_COMMANDS[@]}; do echo "${COMPILE_COMMANDS[command]}" diff --git a/src/lib/java_string.cpp b/src/lib/java_string.cpp index 527de7f..5b4a2f0 100644 --- a/src/lib/java_string.cpp +++ b/src/lib/java_string.cpp @@ -14,17 +14,31 @@ //If not, see https://www.gnu.org/licenses/agpl-3.0.en.html #include +#include #include "error.h++" #include "java_string.h++" namespace JavaCompat { - ErrorOr importJavaFormatToString(uint8_t data[]) { - tiny_utf8::string output; - // do magic - return ErrorOr(output); + tiny_utf8::string importJavaFormatToString(uint8_t data[]) { + std::vector output; + tiny_utf8::string outputString; + uint16_t size = static_cast(data[0])<<8 | static_cast(data[1]); + + for(uint8_t i=2; i exportStringToJavaFormat(tiny_utf8::string data) { return ErrorOr(nullptr); } + */ } diff --git a/src/lib/java_string.h++ b/src/lib/java_string.h++ index a50c37b..b57f56b 100644 --- a/src/lib/java_string.h++ +++ b/src/lib/java_string.h++ @@ -17,6 +17,6 @@ #include "error.h++" namespace JavaCompat { - ErrorOr importJavaFormatToString(uint8_t data[]); + tiny_utf8::string importJavaFormatToString(uint8_t data[]); ErrorOr exportStringToJavaFormat(tiny_utf8::string data); } diff --git a/src/test/java_string.cpp b/src/test/java_string.cpp new file mode 100644 index 0000000..563fab7 --- /dev/null +++ b/src/test/java_string.cpp @@ -0,0 +1,70 @@ +// Copyright 2022, FOSS-VG Developers and Contributers +// +// This program is free software: you can redistribute it and/or modify it +// under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, version 3. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied +// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// version 3 along with this program. +// If not, see https://www.gnu.org/licenses/agpl-3.0.en.html + +#include "assert.h++" +#include "../lib/java_string.h++" +#include +#include +#include +#include + + +int main(){ + + std::cout << "################################################################################" << std::endl; + std::cout << "Java String Tests" << std::endl; + std::cout << "################################################################################" << std::endl; + + std::streampos javaSize; + char* javaData; + std::ifstream javaFile("./resources/unicode_data/java-style_unicode", std::ios::in | std::ios::binary | std::ios::ate); + if(javaFile.is_open()){ + javaSize = javaFile.tellg(); + javaData = new char[javaSize]; + javaFile.seekg(0, std::ios::beg); + javaFile.read(javaData, javaSize); + javaFile.close(); + } + + tiny_utf8::string importString = JavaCompat::importJavaFormatToString((uint8_t*) javaData); + + std::streampos normalSize; + char* normalData; + std::ifstream normalFile("./resources/unicode_data/normal_utf-8", std::ios::in | std::ios::binary | std::ios::ate); + if(normalFile.is_open()){ + normalSize = normalFile.tellg(); + normalData = new char[normalSize]; + normalFile.seekg(0, std::ios::beg); + normalFile.read(normalData, normalSize); + normalFile.close(); + } + + std::vector normalDataVector = std::vector(); + for(int i=0; i