File: Re-add support to skip CR (\r) in File::get_as_text
This was removed in #63481, and we confirmed that it's better like this,
but we add back the possibility to strip CR as an option, to optionally
restore the previous behavior.
For performance this is done directly in `String::parse_utf8`.
Also fixes Android `FileAccess::get_line()` as this one _should_ strip CR.
Supersedes #63717.
(cherry picked from commit 1418f97c70)
This commit is contained in:
@ -378,7 +378,7 @@ uint64_t FileAccess::get_buffer(uint8_t *p_dst, uint64_t p_length) const {
|
||||
return i;
|
||||
}
|
||||
|
||||
String FileAccess::get_as_utf8_string() const {
|
||||
String FileAccess::get_as_utf8_string(bool p_skip_cr) const {
|
||||
PoolVector<uint8_t> sourcef;
|
||||
uint64_t len = get_len();
|
||||
sourcef.resize(len + 1);
|
||||
@ -389,7 +389,7 @@ String FileAccess::get_as_utf8_string() const {
|
||||
w[len] = 0;
|
||||
|
||||
String s;
|
||||
if (s.parse_utf8((const char *)w.ptr())) {
|
||||
if (s.parse_utf8((const char *)w.ptr(), -1, p_skip_cr)) {
|
||||
return String();
|
||||
}
|
||||
return s;
|
||||
|
||||
@ -114,7 +114,7 @@ public:
|
||||
virtual String get_line() const;
|
||||
virtual String get_token() const;
|
||||
virtual Vector<String> get_csv_line(const String &p_delim = ",") const;
|
||||
virtual String get_as_utf8_string() const;
|
||||
virtual String get_as_utf8_string(bool p_skip_cr = true) const; // Skip CR by default for compat.
|
||||
|
||||
/**< use this for files WRITTEN in _big_ endian machines (ie, amiga/mac)
|
||||
* It's not about the current CPU type but file formats.
|
||||
|
||||
Reference in New Issue
Block a user