From 5c73d81e0076eb9cc6b9af018a38f681db2a11e5 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sat, 13 Oct 2007 07:55:58 +0000 Subject: [PATCH] Python style long strings ("""...""") now supported for parsing. Any such strings will be written out as standard strings with escaped quotes when writing the plist. --- include/QF/qfplist.h | 6 ++++-- libs/util/qfplist.c | 14 +++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/include/QF/qfplist.h b/include/QF/qfplist.h index 365c83273..e0e1c3c49 100644 --- a/include/QF/qfplist.h +++ b/include/QF/qfplist.h @@ -60,9 +60,11 @@ An unquoted string may contain only alphanumeric characters and/or the underscore character, '_'. Quoted strings may contain whitespace, C escape - sequences, and so on. The quote character is '"'. + sequences, and so on. The quote character is '"'. Optionally, Python style + long strings ("""...""") may be used, allowing for unquoted '"' quotes in + the string. - QFBinary data is hex-encoded and contained within angle brackets, \< \>. The length of the encoded data must be an even number, so while \ diff --git a/libs/util/qfplist.c b/libs/util/qfplist.c index 972bf45d1..86a2b1da0 100644 --- a/libs/util/qfplist.c +++ b/libs/util/qfplist.c @@ -467,8 +467,16 @@ PL_ParseQuotedString (pldata_t *pl) unsigned int escaped = 0; unsigned int shrink = 0; qboolean hex = false; + qboolean long_string = false; char *str; + if (pl->ptr[pl->pos] == '"' && + pl->ptr[pl->pos + 1] == '"') { + long_string = true; + start += 2; + pl->pos += 2; + } + while (pl->pos < pl->end) { char c = pl->ptr[pl->pos]; @@ -499,7 +507,9 @@ PL_ParseQuotedString (pldata_t *pl) if (c == '\\') { escaped = 1; shrink++; - } else if (c == '"') { + } else if (c == '"' + && (!long_string || (pl->ptr[pl->pos + 1] == '"' + && pl->ptr[pl->pos + 2] == '"'))) { break; } } @@ -594,6 +604,8 @@ PL_ParseQuotedString (pldata_t *pl) str = strncat (calloc ((pl->pos - start - shrink) + 1, 1), chars, pl->pos - start - shrink); } + if (long_string) + pl->pos += 2; pl->pos++; return str; }