This commit is contained in:
blueloveTH 2023-04-26 12:54:10 +08:00
parent a2b25f6735
commit 96c00508be
2 changed files with 8 additions and 4 deletions

View File

@ -31,12 +31,16 @@ struct FileIO {
bool is_text() const { return mode != "rb" && mode != "wb" && mode != "ab"; }
FileIO(VM* vm, Str file, Str mode): file(file), mode(mode) {
std::ios_base::openmode extra = 0;
if(mode == "rb" || mode == "wb" || mode == "ab"){
extra |= std::ios::binary;
}
if(mode == "rt" || mode == "r" || mode == "rb"){
_fs.open(file.sv(), std::ios::in);
_fs.open(file.sv(), std::ios::in | extra);
}else if(mode == "wt" || mode == "w" || mode == "wb"){
_fs.open(file.sv(), std::ios::out);
_fs.open(file.sv(), std::ios::out | extra);
}else if(mode == "at" || mode == "a" || mode == "ab"){
_fs.open(file.sv(), std::ios::app);
_fs.open(file.sv(), std::ios::app | extra);
}else{
vm->ValueError("invalid mode");
}

View File

@ -23,7 +23,7 @@ inline std::string getline(bool* eof=nullptr) {
std::string output;
output.resize(length);
WideCharToMultiByte(CP_UTF8, 0, wideInput.c_str(), (int)wideInput.length(), &output[0], length, NULL, NULL);
if(output.size() && output[output.size()-1] == '\r') output.pop_back();
if(!output.empty() && output.back() == '\r') output.pop_back();
return output;
}