lib/java_string: replace std::vector with std::string
parent
34e30c0bd4
commit
45538e156a
|
@ -14,7 +14,7 @@
|
|||
//If not, see https://www.gnu.org/licenses/agpl-3.0.en.html
|
||||
|
||||
#include <tinyutf8/tinyutf8.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "error.h++"
|
||||
|
||||
#include "java_string.h++"
|
||||
|
@ -23,20 +23,19 @@ 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::vector<uint8_t> output;
|
||||
tiny_utf8::string outputString;
|
||||
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; i++){
|
||||
if(i != 0){
|
||||
if(data[i] == 0x80 && data[i-1] == 0xc0){
|
||||
output[output.size() - 1] = 0x00;
|
||||
stdString[stdString.length() - 1] = '\0';
|
||||
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) {
|
||||
|
|
|
@ -52,7 +52,7 @@ int main(){
|
|||
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::string normalStdString;
|
||||
|
|
Loading…
Reference in New Issue