From 559cf87d8644ae06c31aa499a83f0072507cf91b Mon Sep 17 00:00:00 2001 From: "wtc%netscape.com" Date: Mon, 14 Dec 1998 22:49:47 +0000 Subject: [PATCH] Minor cleanup/fix in DoScanf. --- nsprpub/pr/src/io/prscanf.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/nsprpub/pr/src/io/prscanf.c b/nsprpub/pr/src/io/prscanf.c index 96530bf6a66d..833d2763f2cc 100644 --- a/nsprpub/pr/src/io/prscanf.c +++ b/nsprpub/pr/src/io/prscanf.c @@ -387,6 +387,7 @@ GetFloat(ScanfState *state) /* * Convert, and return the end of the conversion spec. + * Return NULL on error. */ static const char * @@ -544,6 +545,7 @@ DoScanf(ScanfState *state, const char *fmt) cPtr = fmt; while (1) { if (isspace(*cPtr)) { + /* white space: skip */ do { cPtr++; } while (isspace(*cPtr)); @@ -551,20 +553,12 @@ DoScanf(ScanfState *state, const char *fmt) ch = GET(state); } while (isspace(ch)); UNGET(state, ch); - } else if (*cPtr != '%') { - if (*cPtr == '\0') { - return nConverted; - } - ch = GET(state); - if (ch != *cPtr) { - UNGET(state, ch); - return nConverted; - } - cPtr++; - } else { + } else if (*cPtr == '%') { + /* format spec: convert */ cPtr++; state->assign = PR_TRUE; if (*cPtr == '*') { + cPtr++; state->assign = PR_FALSE; } for (state->width = 0; isdigit(*cPtr); cPtr++) { @@ -594,6 +588,17 @@ DoScanf(ScanfState *state, const char *fmt) nConverted++; } cPtr++; + } else { + /* others: must match */ + if (*cPtr == '\0') { + return nConverted; + } + ch = GET(state); + if (ch != *cPtr) { + UNGET(state, ch); + return nConverted; + } + cPtr++; } } }