Skip to content

Commit

Permalink
Ignore whitespace between formats (not internal to a count+format).
Browse files Browse the repository at this point in the history
  • Loading branch information
gvanrossum committed Aug 26, 1997
1 parent ab0abdc commit e20aef5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Doc/lib/libstruct.tex
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ \section{Built-in Module \sectcode{struct}}
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
Expand Down
3 changes: 3 additions & 0 deletions Doc/libstruct.tex
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ \section{Built-in Module \sectcode{struct}}
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
Expand Down
7 changes: 7 additions & 0 deletions Modules/structmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ PERFORMANCE OF THIS SOFTWARE.
#include "mymath.h"

#include <limits.h>
#include <ctype.h>


/* Exception */
Expand Down Expand Up @@ -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') {
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit e20aef5

Please sign in to comment.