mirror of
https://github.com/godotengine/godot.git
synced 2025-12-08 06:09:55 +00:00
Core: Remove skip_cr argument from String
This commit is contained in:
parent
9283328fe7
commit
f6fc2f4a08
11 changed files with 99 additions and 59 deletions
|
|
@ -90,6 +90,14 @@ void FileAccess::store_pascal_string_bind_compat_78289(const String &p_string) {
|
|||
store_pascal_string(p_string);
|
||||
}
|
||||
|
||||
String FileAccess::get_as_text_bind_compat_110867(bool p_skip_cr) const {
|
||||
String text = get_as_text();
|
||||
if (unlikely(p_skip_cr)) {
|
||||
text = text.remove_char('\r');
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
void FileAccess::_bind_compatibility_methods() {
|
||||
ClassDB::bind_compatibility_static_method("FileAccess", D_METHOD("open_encrypted", "path", "mode_flags", "key"), &FileAccess::_open_encrypted_bind_compat_98918);
|
||||
|
||||
|
|
@ -107,6 +115,7 @@ void FileAccess::_bind_compatibility_methods() {
|
|||
ClassDB::bind_compatibility_method(D_METHOD("store_string", "string"), &FileAccess::store_string_bind_compat_78289);
|
||||
ClassDB::bind_compatibility_method(D_METHOD("store_var", "value", "full_objects"), &FileAccess::store_var_bind_compat_78289, DEFVAL(false));
|
||||
ClassDB::bind_compatibility_method(D_METHOD("store_pascal_string", "string"), &FileAccess::store_pascal_string_bind_compat_78289);
|
||||
ClassDB::bind_compatibility_method(D_METHOD("get_as_text", "skip_cr"), &FileAccess::get_as_text_bind_compat_110867, DEFVAL(false));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -467,10 +467,22 @@ String FileAccess::get_line() const {
|
|||
uint8_t c = get_8();
|
||||
|
||||
while (!eof_reached()) {
|
||||
if (c == '\n' || c == '\0' || get_error() != OK) {
|
||||
if (c == '\r' || c == '\n' || c == '\0' || get_error() != OK) {
|
||||
if (c == '\r') {
|
||||
// Check for Windows-style EOL.
|
||||
const uint64_t prev_pos = get_position() - 1;
|
||||
if (unlikely(get_8() != '\n')) {
|
||||
// HACK: We can't simply check the next value in a vacuum, so we risk triggering
|
||||
// an EOL false-positive in the unlikely event that this `\r` was the final
|
||||
// value of the file. Unilaterally work around by re-reading the *previous*
|
||||
// byte (the starting `\r`) to ensure `get_error()` returns `OK`.
|
||||
const_cast<FileAccess *>(this)->seek(prev_pos);
|
||||
get_8();
|
||||
}
|
||||
}
|
||||
line.push_back(0);
|
||||
return String::utf8(line.get_data());
|
||||
} else if (c != '\r') {
|
||||
} else {
|
||||
line.push_back(char(c));
|
||||
}
|
||||
|
||||
|
|
@ -538,11 +550,11 @@ Vector<String> FileAccess::get_csv_line(const String &p_delim) const {
|
|||
return strings;
|
||||
}
|
||||
|
||||
String FileAccess::get_as_text(bool p_skip_cr) const {
|
||||
String FileAccess::get_as_text() const {
|
||||
uint64_t original_pos = get_position();
|
||||
const_cast<FileAccess *>(this)->seek(0);
|
||||
|
||||
String text = get_as_utf8_string(p_skip_cr);
|
||||
String text = get_as_utf8_string();
|
||||
|
||||
const_cast<FileAccess *>(this)->seek(original_pos);
|
||||
|
||||
|
|
@ -570,7 +582,7 @@ Vector<uint8_t> FileAccess::get_buffer(int64_t p_length) const {
|
|||
return data;
|
||||
}
|
||||
|
||||
String FileAccess::get_as_utf8_string(bool p_skip_cr) const {
|
||||
String FileAccess::get_as_utf8_string() const {
|
||||
Vector<uint8_t> sourcef;
|
||||
uint64_t len = get_length();
|
||||
sourcef.resize(len + 1);
|
||||
|
|
@ -581,7 +593,7 @@ String FileAccess::get_as_utf8_string(bool p_skip_cr) const {
|
|||
w[len] = 0;
|
||||
|
||||
String s;
|
||||
s.append_utf8((const char *)w, len, p_skip_cr);
|
||||
s.append_utf8((const char *)w, len);
|
||||
return s;
|
||||
}
|
||||
|
||||
|
|
@ -987,7 +999,7 @@ void FileAccess::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("get_buffer", "length"), (Vector<uint8_t> (FileAccess::*)(int64_t) const) & FileAccess::get_buffer);
|
||||
ClassDB::bind_method(D_METHOD("get_line"), &FileAccess::get_line);
|
||||
ClassDB::bind_method(D_METHOD("get_csv_line", "delim"), &FileAccess::get_csv_line, DEFVAL(","));
|
||||
ClassDB::bind_method(D_METHOD("get_as_text", "skip_cr"), &FileAccess::get_as_text, DEFVAL(false));
|
||||
ClassDB::bind_method(D_METHOD("get_as_text"), &FileAccess::get_as_text);
|
||||
ClassDB::bind_static_method("FileAccess", D_METHOD("get_md5", "path"), &FileAccess::get_md5);
|
||||
ClassDB::bind_static_method("FileAccess", D_METHOD("get_sha256", "path"), &FileAccess::get_sha256);
|
||||
ClassDB::bind_method(D_METHOD("is_big_endian"), &FileAccess::is_big_endian);
|
||||
|
|
|
|||
|
|
@ -132,6 +132,7 @@ protected:
|
|||
void store_line_bind_compat_78289(const String &p_line);
|
||||
void store_csv_line_bind_compat_78289(const Vector<String> &p_values, const String &p_delim = ",");
|
||||
void store_pascal_string_bind_compat_78289(const String &p_string);
|
||||
String get_as_text_bind_compat_110867(bool p_skip_cr) const;
|
||||
|
||||
static void _bind_compatibility_methods();
|
||||
#endif
|
||||
|
|
@ -188,8 +189,8 @@ public:
|
|||
virtual String get_line() const;
|
||||
virtual String get_token() const;
|
||||
virtual Vector<String> get_csv_line(const String &p_delim = ",") const;
|
||||
String get_as_text(bool p_skip_cr = false) const;
|
||||
virtual String get_as_utf8_string(bool p_skip_cr = false) const;
|
||||
String get_as_text() const;
|
||||
virtual String get_as_utf8_string() const;
|
||||
|
||||
/**
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue