Birthed an abomination, what the fuck
parent
a3a9078965
commit
42336c560a
|
@ -39,6 +39,7 @@ echo "Building tests..."
|
||||||
COMPILE_COMMANDS=(
|
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/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/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
|
for command in ${!COMPILE_COMMANDS[@]}; do
|
||||||
echo "${COMPILE_COMMANDS[command]}"
|
echo "${COMPILE_COMMANDS[command]}"
|
||||||
|
|
|
@ -14,17 +14,31 @@
|
||||||
//If not, see https://www.gnu.org/licenses/agpl-3.0.en.html
|
//If not, see https://www.gnu.org/licenses/agpl-3.0.en.html
|
||||||
|
|
||||||
#include <tinyutf8/tinyutf8.h>
|
#include <tinyutf8/tinyutf8.h>
|
||||||
|
#include <vector>
|
||||||
#include "error.h++"
|
#include "error.h++"
|
||||||
|
|
||||||
#include "java_string.h++"
|
#include "java_string.h++"
|
||||||
|
|
||||||
namespace JavaCompat {
|
namespace JavaCompat {
|
||||||
ErrorOr<tiny_utf8::string> importJavaFormatToString(uint8_t data[]) {
|
tiny_utf8::string importJavaFormatToString(uint8_t data[]) {
|
||||||
tiny_utf8::string output;
|
std::vector<uint8_t> output;
|
||||||
// do magic
|
tiny_utf8::string outputString;
|
||||||
return ErrorOr(output);
|
uint16_t size = static_cast<uint16_t>(data[0])<<8 | static_cast<uint16_t>(data[1]);
|
||||||
|
|
||||||
|
for(uint8_t i=2; i<size; i++){
|
||||||
|
if(i != 0){
|
||||||
|
if(data[i] == 0x80 && data[i-1] == 0xc0){
|
||||||
|
output[output.size() - 1] = 0x00;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
output.push_back(data[i]);
|
||||||
|
}
|
||||||
|
return tiny_utf8::string(output.begin(), output.end());
|
||||||
|
}
|
||||||
|
/*
|
||||||
ErrorOr<uint8_t*> exportStringToJavaFormat(tiny_utf8::string data) {
|
ErrorOr<uint8_t*> exportStringToJavaFormat(tiny_utf8::string data) {
|
||||||
return ErrorOr(nullptr);
|
return ErrorOr(nullptr);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,6 @@
|
||||||
#include "error.h++"
|
#include "error.h++"
|
||||||
|
|
||||||
namespace JavaCompat {
|
namespace JavaCompat {
|
||||||
ErrorOr<tiny_utf8::string> importJavaFormatToString(uint8_t data[]);
|
tiny_utf8::string importJavaFormatToString(uint8_t data[]);
|
||||||
ErrorOr<uint8_t*> exportStringToJavaFormat(tiny_utf8::string data);
|
ErrorOr<uint8_t*> exportStringToJavaFormat(tiny_utf8::string data);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 <iostream>
|
||||||
|
#include <tinyutf8/tinyutf8.h>
|
||||||
|
#include <fstream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
|
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<char> normalDataVector = std::vector<char>();
|
||||||
|
for(int i=0; i<normalSize; i++){
|
||||||
|
normalDataVector.push_back(normalData[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
tiny_utf8::string normalString = tiny_utf8::string(normalDataVector.begin(), normalDataVector.end());
|
||||||
|
|
||||||
|
std::cout << normalString.size() << std::endl;
|
||||||
|
std::cout << importString.size() << std::endl;
|
||||||
|
|
||||||
|
ASSERT(normalString == importString);
|
||||||
|
std::cout << "Passed Import Java string test." << std::endl;
|
||||||
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue