diff options
author | Jerry DeLisle <jvdelisle@gcc.gnu.org> | 2024-02-13 14:32:21 -0800 |
---|---|---|
committer | Jerry DeLisle <jvdelisle@gcc.gnu.org> | 2024-02-14 07:57:53 -0800 |
commit | b79d3e6a9284703b70688122f7d4955e7c50804a (patch) | |
tree | 11cbb3dc71fe7c484465502c546e799a9c995966 /libgfortran | |
parent | eafbb05c49957096d5118dfa661c0efba774bd8b (diff) |
Fortran: Implement read_x for UTF-8 encoded files.
PR fortran/99210
libgfortran/ChangeLog:
* io/read.c (read_x): If UTF-8 encoding is enabled, use
read_utf8 to move one character over in the read buffer.
gcc/testsuite/ChangeLog:
* gfortran.dg/pr99210.f90: New test.
Diffstat (limited to 'libgfortran')
-rw-r--r-- | libgfortran/io/read.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/libgfortran/io/read.c b/libgfortran/io/read.c index 0ffcf76fd38..e2d2f8be806 100644 --- a/libgfortran/io/read.c +++ b/libgfortran/io/read.c @@ -1307,6 +1307,23 @@ read_x (st_parameter_dt *dtp, size_t n) if (n == 0) return; + + if (dtp->u.p.current_unit->flags.encoding == ENCODING_UTF8) + { + gfc_char4_t c; + size_t nbytes, j; + + /* Proceed with decoding one character at a time. */ + for (j = 0; j < n; j++) + { + c = read_utf8 (dtp, &nbytes); + + /* Check for a short read and if so, break out. */ + if (nbytes == 0 || c == (gfc_char4_t)0) + break; + } + return; + } length = n; |