mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-22 12:30:19 +00:00
...
This commit is contained in:
parent
a2b25f6735
commit
96c00508be
10
src/io.h
10
src/io.h
@ -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");
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user