Mercurial > hg > octave-lyh
comparison scripts/io/strread.m @ 16571:4d8462fe15b9
strread.m: catch unknown format specifiers (bug #38834)
author | Philip Nienhuis <prnienhuis@users.sf.net> |
---|---|
date | Fri, 26 Apr 2013 14:25:09 +0200 |
parents | 61989cde13ae |
children | b7667fcb9fbc |
comparison
equal
deleted
inserted
replaced
16570:d5ae5aa80d42 | 16571:4d8462fe15b9 |
---|---|
313 a = strfind (fmt_words(idy2), "%"); | 313 a = strfind (fmt_words(idy2), "%"); |
314 b = regexp (fmt_words(idy2), '[nfdus]', "end"); | 314 b = regexp (fmt_words(idy2), '[nfdus]', "end"); |
315 for jj = 1:numel (a) | 315 for jj = 1:numel (a) |
316 ## From right to left to avoid losing track | 316 ## From right to left to avoid losing track |
317 ii = numel (a) - jj + 1; | 317 ii = numel (a) - jj + 1; |
318 ## Check for illegal format specifiers | |
319 if (isempty (b{ii})) | |
320 error ("strread: unknown format specifier #%d ('%s')\n", | |
321 ii, fmt_words{idy2(ii)}); | |
322 endif | |
318 if (! (length (fmt_words{idy2(ii)}) == b{ii}(1))) | 323 if (! (length (fmt_words{idy2(ii)}) == b{ii}(1))) |
319 ## Split fmt_words(ii) into % conv specifier and trailing literal | 324 ## Split fmt_words(ii) into % conv specifier and trailing literal |
320 fmt_words(idy2(ii)+1 : end+1) = fmt_words(idy2(ii) : end); | 325 fmt_words(idy2(ii)+1 : end+1) = fmt_words(idy2(ii) : end); |
321 fmt_words{idy2(ii)} = fmt_words{idy2(ii)}(a{ii} : b{ii}(1)); | 326 fmt_words{idy2(ii)} = fmt_words{idy2(ii)}(a{ii} : b{ii}(1)); |
322 fmt_words{idy2(ii)+1} = fmt_words{idy2(ii)+1}(b{ii}+1:end); | 327 fmt_words{idy2(ii)+1} = fmt_words{idy2(ii)+1}(b{ii}+1:end); |
983 %!error <format specifiers are not supported> strread ("a", "%*d8 %s") | 988 %!error <format specifiers are not supported> strread ("a", "%*d8 %s") |
984 %!error <format specifiers are not supported> strread ("a", "%f64") | 989 %!error <format specifiers are not supported> strread ("a", "%f64") |
985 %!error <format specifiers are not supported> strread ("a", "%*f64 %s") | 990 %!error <format specifiers are not supported> strread ("a", "%*f64 %s") |
986 %!error <format specifiers are not supported> strread ("a", "%u32") | 991 %!error <format specifiers are not supported> strread ("a", "%u32") |
987 %!error <format specifiers are not supported> strread ("a", "%*u32 %d") | 992 %!error <format specifiers are not supported> strread ("a", "%*u32 %d") |
993 | |
994 %% Illegal format specifiers | |
995 %!test | |
996 %!error <unknown format specifier> strread ("1.0", "%z") |