46 lines
1.6 KiB
C++
46 lines
1.6 KiB
C++
//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 <tinyutf8/tinyutf8.h>
|
|
#include <string>
|
|
#include "error.h++"
|
|
|
|
#include "java_string.h++"
|
|
|
|
namespace JavaCompat {
|
|
//FIXME: contrary to what I said, we need to explicitly pass the data
|
|
// size because files could have been tampered with or corrupted
|
|
tiny_utf8::string importJavaString(uint8_t data[]) {
|
|
std::string stdString;
|
|
uint16_t size = static_cast<uint16_t>(data[0])<<8 | static_cast<uint16_t>(data[1]);
|
|
|
|
for(uint8_t i=2; i<size+2; i++){
|
|
if(i != 0){
|
|
if(data[i] == 0x80 && data[i-1] == 0xc0){
|
|
stdString[stdString.length() - 1] = '\0';
|
|
continue;
|
|
}
|
|
}
|
|
stdString.push_back((char) data[i]);
|
|
}
|
|
return tiny_utf8::string(stdString);
|
|
}
|
|
/*
|
|
ErrorOr<uint8_t*> exportJavaString(tiny_utf8::string data) {
|
|
return ErrorOr(nullptr);
|
|
}
|
|
*/
|
|
}
|