mirror of
https://github.com/godotengine/godot.git
synced 2025-10-19 16:03:29 +00:00
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.
This commit is contained in:
parent
14828c331c
commit
1418f97c70
15 changed files with 74 additions and 13 deletions
|
@ -1656,7 +1656,7 @@ String String::utf8(const char *p_utf8, int p_len) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
Error String::parse_utf8(const char *p_utf8, int p_len) {
|
||||
Error String::parse_utf8(const char *p_utf8, int p_len, bool p_skip_cr) {
|
||||
if (!p_utf8) {
|
||||
return ERR_INVALID_DATA;
|
||||
}
|
||||
|
@ -1689,6 +1689,10 @@ Error String::parse_utf8(const char *p_utf8, int p_len) {
|
|||
uint8_t c = *ptrtmp >= 0 ? *ptrtmp : uint8_t(256 + *ptrtmp);
|
||||
|
||||
if (skip == 0) {
|
||||
if (p_skip_cr && c == '\r') {
|
||||
ptrtmp++;
|
||||
continue;
|
||||
}
|
||||
/* Determine the number of characters in sequence */
|
||||
if ((c & 0x80) == 0) {
|
||||
skip = 0;
|
||||
|
@ -1753,6 +1757,10 @@ Error String::parse_utf8(const char *p_utf8, int p_len) {
|
|||
uint8_t c = *p_utf8 >= 0 ? *p_utf8 : uint8_t(256 + *p_utf8);
|
||||
|
||||
if (skip == 0) {
|
||||
if (p_skip_cr && c == '\r') {
|
||||
p_utf8++;
|
||||
continue;
|
||||
}
|
||||
/* Determine the number of characters in sequence */
|
||||
if ((c & 0x80) == 0) {
|
||||
*(dst++) = c;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue