Mercurial > octave
changeset 32166:e8497a0fb249 stable
native2unicode, unicode2native: Support empty second argument (bug #64331).
* scripts/strings/native2unicode.m, scripts/strings/unicode2native.m: Restore
support for empty second argument. Add BIST.
author | Markus Mützel <markus.muetzel@gmx.de> |
---|---|
date | Fri, 23 Jun 2023 20:51:15 +0200 |
parents | fab3e312a0b4 |
children | 59681cc864e7 6ad3035405a5 |
files | scripts/strings/native2unicode.m scripts/strings/unicode2native.m |
diffstat | 2 files changed, 8 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/strings/native2unicode.m Fri Jun 23 16:19:46 2023 +0200 +++ b/scripts/strings/native2unicode.m Fri Jun 23 20:51:15 2023 +0200 @@ -58,7 +58,7 @@ error ("native2unicode: NATIVE_BYTES must be a numeric vector"); endif - if (nargin == 2 && ! (ischar (codepage) && isrow (codepage))) + if (! (ischar (codepage) && (isrow (codepage) || isempty (codepage)))) error ("native2unicode: CODEPAGE must be a string"); endif @@ -86,6 +86,10 @@ %!assert (native2unicode ("foobar"), "foobar") %!assert <*54384> (double (native2unicode ([0 0 120.3 0 0 122.6 0 0])), %! [0 0 120 0 0 123 0 0]) +%!testif HAVE_ICONV <*64331> +%! assert (! isempty (native2unicode (97:99))); +%!testif HAVE_ICONV <*64331> +%! assert (! isempty (native2unicode (97:99, ""))); %!error <Invalid call> native2unicode () %!error <called with too many inputs> native2unicode (1, 'ISO-8859-1', 'test')
--- a/scripts/strings/unicode2native.m Fri Jun 23 16:19:46 2023 +0200 +++ b/scripts/strings/unicode2native.m Fri Jun 23 20:51:15 2023 +0200 @@ -59,7 +59,7 @@ error ("unicode2native: UTF8_STR must be a character vector"); endif - if (nargin > 1 && ! (ischar (codepage) && isrow (codepage))) + if (! (ischar (codepage) && (isrow (codepage) || isempty (codepage)))) error ("unicode2native: CODEPAGE must be a string"); endif @@ -80,6 +80,8 @@ %!assert <*60480> (unicode2native (''), uint8 ([])) %!testif HAVE_ICONV <*64331> %! assert (! isempty (unicode2native ("abc"))); +%!testif HAVE_ICONV <*64331> +%! assert (! isempty (unicode2native ("abc", ""))); # short character arrays with invalid UTF-8 %!testif HAVE_ICONV <*63930>