Merge pull request #63733 from akien-mga/file-get_as_text-skip-CR
File: Re-add support to skip CR (`\r`) in `File::get_as_text`
This commit is contained in:
@ -78,6 +78,29 @@ TEST_CASE("[FileAccess] CSV read") {
|
||||
CHECK(row5[1] == "tab separated");
|
||||
CHECK(row5[2] == "lines, good?");
|
||||
}
|
||||
|
||||
TEST_CASE("[FileAccess] Get as UTF-8 String") {
|
||||
Ref<FileAccess> f_lf = FileAccess::open(TestUtils::get_data_path("line_endings_lf.test.txt"), FileAccess::READ);
|
||||
String s_lf = f_lf->get_as_utf8_string();
|
||||
f_lf->seek(0);
|
||||
String s_lf_nocr = f_lf->get_as_utf8_string(true);
|
||||
CHECK(s_lf == "Hello darkness\nMy old friend\nI've come to talk\nWith you again\n");
|
||||
CHECK(s_lf_nocr == "Hello darkness\nMy old friend\nI've come to talk\nWith you again\n");
|
||||
|
||||
Ref<FileAccess> f_crlf = FileAccess::open(TestUtils::get_data_path("line_endings_crlf.test.txt"), FileAccess::READ);
|
||||
String s_crlf = f_crlf->get_as_utf8_string();
|
||||
f_crlf->seek(0);
|
||||
String s_crlf_nocr = f_crlf->get_as_utf8_string(true);
|
||||
CHECK(s_crlf == "Hello darkness\r\nMy old friend\r\nI've come to talk\r\nWith you again\r\n");
|
||||
CHECK(s_crlf_nocr == "Hello darkness\nMy old friend\nI've come to talk\nWith you again\n");
|
||||
|
||||
Ref<FileAccess> f_cr = FileAccess::open(TestUtils::get_data_path("line_endings_cr.test.txt"), FileAccess::READ);
|
||||
String s_cr = f_cr->get_as_utf8_string();
|
||||
f_cr->seek(0);
|
||||
String s_cr_nocr = f_cr->get_as_utf8_string(true);
|
||||
CHECK(s_cr == "Hello darkness\rMy old friend\rI've come to talk\rWith you again\r");
|
||||
CHECK(s_cr_nocr == "Hello darknessMy old friendI've come to talkWith you again");
|
||||
}
|
||||
} // namespace TestFileAccess
|
||||
|
||||
#endif // TEST_FILE_ACCESS_H
|
||||
|
||||
@ -152,6 +152,20 @@ TEST_CASE("[String] UTF16 with BOM") {
|
||||
CHECK(String::utf16(cs) == s);
|
||||
}
|
||||
|
||||
TEST_CASE("[String] UTF8 with CR") {
|
||||
const String base = U"Hello darkness\r\nMy old friend\nI've come to talk\rWith you again";
|
||||
|
||||
String keep_cr;
|
||||
Error err = keep_cr.parse_utf8(base.utf8().get_data());
|
||||
CHECK(err == OK);
|
||||
CHECK(keep_cr == base);
|
||||
|
||||
String no_cr;
|
||||
err = no_cr.parse_utf8(base.utf8().get_data(), -1, true); // Skip CR.
|
||||
CHECK(err == OK);
|
||||
CHECK(no_cr == base.replace("\r", ""));
|
||||
}
|
||||
|
||||
TEST_CASE("[String] Invalid UTF8 (non-standard)") {
|
||||
ERR_PRINT_OFF
|
||||
static const uint8_t u8str[] = { 0x45, 0xE3, 0x81, 0x8A, 0xE3, 0x82, 0x88, 0xE3, 0x81, 0x86, 0xF0, 0x9F, 0x8E, 0xA4, 0xF0, 0x82, 0x82, 0xAC, 0xED, 0xA0, 0x81, 0 };
|
||||
|
||||
1
tests/data/line_endings_cr.test.txt
Normal file
1
tests/data/line_endings_cr.test.txt
Normal file
@ -0,0 +1 @@
|
||||
Hello darkness
|
||||
4
tests/data/line_endings_crlf.test.txt
Normal file
4
tests/data/line_endings_crlf.test.txt
Normal file
@ -0,0 +1,4 @@
|
||||
Hello darkness
|
||||
My old friend
|
||||
I've come to talk
|
||||
With you again
|
||||
4
tests/data/line_endings_lf.test.txt
Normal file
4
tests/data/line_endings_lf.test.txt
Normal file
@ -0,0 +1,4 @@
|
||||
Hello darkness
|
||||
My old friend
|
||||
I've come to talk
|
||||
With you again
|
||||
Reference in New Issue
Block a user