Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e20aef5

Browse files
committed
Ignore whitespace between formats (not internal to a count+format).
1 parent ab0abdc commit e20aef5

3 files changed

Lines changed: 13 additions & 0 deletions

File tree

Doc/lib/libstruct.tex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ \section{Built-in Module \sectcode{struct}}
6161
A format character may be preceded by an integral repeat count; e.g.\
6262
the format string \code{'4h'} means exactly the same as \code{'hhhh'}.
6363

64+
Whitespace characters between formats are ignored; a count and its
65+
format must not contain whitespace though.
66+
6467
For the \code{'s'} format character, the count is interpreted as the
6568
size of the string, not a repeat count like for the other format
6669
characters; e.g. \code{'10s'} means a single 10-byte string, while

Doc/libstruct.tex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ \section{Built-in Module \sectcode{struct}}
6161
A format character may be preceded by an integral repeat count; e.g.\
6262
the format string \code{'4h'} means exactly the same as \code{'hhhh'}.
6363

64+
Whitespace characters between formats are ignored; a count and its
65+
format must not contain whitespace though.
66+
6467
For the \code{'s'} format character, the count is interpreted as the
6568
size of the string, not a repeat count like for the other format
6669
characters; e.g. \code{'10s'} means a single 10-byte string, while

Modules/structmodule.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ PERFORMANCE OF THIS SOFTWARE.
3838
#include "mymath.h"
3939

4040
#include <limits.h>
41+
#include <ctype.h>
4142

4243

4344
/* Exception */
@@ -981,6 +982,8 @@ calcsize(fmt, f)
981982
s = fmt;
982983
size = 0;
983984
while ((c = *s++) != '\0') {
985+
if (isspace(c))
986+
continue;
984987
if ('0' <= c && c <= '9') {
985988
num = c - '0';
986989
while ('0' <= (c = *s++) && c <= '9') {
@@ -1075,6 +1078,8 @@ struct_pack(self, args)
10751078
res = restart = PyString_AsString(result);
10761079

10771080
while ((c = *s++) != '\0') {
1081+
if (isspace(c))
1082+
continue;
10781083
if ('0' <= c && c <= '9') {
10791084
num = c - '0';
10801085
while ('0' <= (c = *s++) && c <= '9')
@@ -1179,6 +1184,8 @@ struct_unpack(self, args)
11791184
str = start;
11801185
s = fmt;
11811186
while ((c = *s++) != '\0') {
1187+
if (isspace(c))
1188+
continue;
11821189
if ('0' <= c && c <= '9') {
11831190
num = c - '0';
11841191
while ('0' <= (c = *s++) && c <= '9')

0 commit comments

Comments
 (0)