From e20aef574a1373139ae17c6c4a02d83fe5668164 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Tue, 26 Aug 1997 20:39:54 +0000 Subject: Ignore whitespace between formats (not internal to a count+format). --- Doc/lib/libstruct.tex | 3 +++ Doc/libstruct.tex | 3 +++ Modules/structmodule.c | 7 +++++++ 3 files changed, 13 insertions(+) diff --git a/Doc/lib/libstruct.tex b/Doc/lib/libstruct.tex index d57a2b7..af2e6d2 100644 --- a/Doc/lib/libstruct.tex +++ b/Doc/lib/libstruct.tex @@ -61,6 +61,9 @@ and Python values should be obvious given their types: A format character may be preceded by an integral repeat count; e.g.\ the format string \code{'4h'} means exactly the same as \code{'hhhh'}. +Whitespace characters between formats are ignored; a count and its +format must not contain whitespace though. + For the \code{'s'} format character, the count is interpreted as the size of the string, not a repeat count like for the other format characters; e.g. \code{'10s'} means a single 10-byte string, while diff --git a/Doc/libstruct.tex b/Doc/libstruct.tex index d57a2b7..af2e6d2 100644 --- a/Doc/libstruct.tex +++ b/Doc/libstruct.tex @@ -61,6 +61,9 @@ and Python values should be obvious given their types: A format character may be preceded by an integral repeat count; e.g.\ the format string \code{'4h'} means exactly the same as \code{'hhhh'}. +Whitespace characters between formats are ignored; a count and its +format must not contain whitespace though. + For the \code{'s'} format character, the count is interpreted as the size of the string, not a repeat count like for the other format characters; e.g. \code{'10s'} means a single 10-byte string, while diff --git a/Modules/structmodule.c b/Modules/structmodule.c index dbba9b4..54ca631 100644 --- a/Modules/structmodule.c +++ b/Modules/structmodule.c @@ -38,6 +38,7 @@ PERFORMANCE OF THIS SOFTWARE. #include "mymath.h" #include +#include /* Exception */ @@ -981,6 +982,8 @@ calcsize(fmt, f) s = fmt; size = 0; while ((c = *s++) != '\0') { + if (isspace(c)) + continue; if ('0' <= c && c <= '9') { num = c - '0'; while ('0' <= (c = *s++) && c <= '9') { @@ -1075,6 +1078,8 @@ struct_pack(self, args) res = restart = PyString_AsString(result); while ((c = *s++) != '\0') { + if (isspace(c)) + continue; if ('0' <= c && c <= '9') { num = c - '0'; while ('0' <= (c = *s++) && c <= '9') @@ -1179,6 +1184,8 @@ struct_unpack(self, args) str = start; s = fmt; while ((c = *s++) != '\0') { + if (isspace(c)) + continue; if ('0' <= c && c <= '9') { num = c - '0'; while ('0' <= (c = *s++) && c <= '9') -- cgit v0.12