1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-11 13:10:58 +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.

(cherry picked from commit 1418f97c70)
This commit is contained in:
Rémi Verschelde
2022-07-31 18:46:53 +02:00
parent f9db8fa70a
commit 751b16a285
8 changed files with 26 additions and 13 deletions

View File

@@ -1430,7 +1430,7 @@ String String::utf8(const char *p_utf8, int p_len) {
return ret;
};
bool String::parse_utf8(const char *p_utf8, int p_len) {
bool String::parse_utf8(const char *p_utf8, int p_len, bool p_skip_cr) {
#define _UNICERROR(m_err) print_line("Unicode error: " + String(m_err));
if (!p_utf8) {
@@ -1462,6 +1462,11 @@ bool String::parse_utf8(const char *p_utf8, int p_len) {
if (skip == 0) {
uint8_t c = *ptrtmp >= 0 ? *ptrtmp : uint8_t(256 + *ptrtmp);
if (p_skip_cr && c == '\r') {
ptrtmp++;
continue;
}
/* Determine the number of characters in sequence */
if ((c & 0x80) == 0) {
skip = 0;
@@ -1519,6 +1524,11 @@ bool String::parse_utf8(const char *p_utf8, int p_len) {
while (cstr_size) {
int len = 0;
if (p_skip_cr && *p_utf8 == '\r') {
p_utf8++;
continue;
}
/* Determine the number of characters in sequence */
if ((*p_utf8 & 0x80) == 0) {
len = 1;