lib/java_string: replace std::vector with std::string

BodgeMaster-unfinished
BodgeMaster 2022-07-20 04:23:06 +02:00
parent 34e30c0bd4
commit 45538e156a
2 changed files with 6 additions and 7 deletions

View File

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

View File

@ -52,7 +52,7 @@ int main(){
return 2; return 2;
} }
tiny_utf8::string importedString = JavaCompat::importJavaFormat(reinterpret_cast<uint8_t*>(javaStdString.data())); tiny_utf8::string importedString = JavaCompat::importJavaString(reinterpret_cast<uint8_t*>(javaStdString.data()));
std::streampos normalSize; std::streampos normalSize;
std::string normalStdString; std::string normalStdString;