diff options
author | Haru <haru@dotalux.com> | 2013-09-15 20:24:41 +0200 |
---|---|---|
committer | Haru <haru@dotalux.com> | 2013-11-28 02:35:01 +0100 |
commit | 09dd2097b77bf3dda4c5eb1ee6eb2a60f05bbec8 (patch) | |
tree | 5864b4bdae94373089b2de7c9b7ec986b033a235 /src/map/script.c | |
parent | 9a802b9147221ec1f31109242be2919f53401fd3 (diff) | |
download | hercules-09dd2097b77bf3dda4c5eb1ee6eb2a60f05bbec8.tar.gz hercules-09dd2097b77bf3dda4c5eb1ee6eb2a60f05bbec8.tar.bz2 hercules-09dd2097b77bf3dda4c5eb1ee6eb2a60f05bbec8.tar.xz hercules-09dd2097b77bf3dda4c5eb1ee6eb2a60f05bbec8.zip |
Added support for automatic concatenation of adjacent string literals
- [ This commit is part of a larger script engine related update ]
- Adjacent string literals are now automatically concatenated into one
string upon parsing.
- Adjacent string literals are string literals (i.e. "such as this",
with only whitespace (including line breaks and/or comments) between
them. For example, the lines:
mes "this will be concatenated " /* skipping this
comment */ " into one string"; // at parse time
will produce an output of "this will be concatenated into one string".
- The feature brings parity with other languages (i.e. C), and makes it
easier to split long strings in multiple lines, without having to
resort to a, slower, run-time string concatenation operator ('+')
- Special thanks to Trojal for the idea.
Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/map/script.c')
-rw-r--r-- | src/map/script.c | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/src/map/script.c b/src/map/script.c index 73aaafab2..007a3a3d3 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -1070,26 +1070,29 @@ const char* parse_simpleexpr(const char *p) { p=np; } else if(*p=='"') { script->addc(C_STR); - p++; - while( *p && *p != '"' ) { - if( (unsigned char)p[-1] <= 0x7e && *p == '\\' ) { - char buf[8]; - size_t len = sv->skip_escaped_c(p) - p; - size_t n = sv->unescape_c(buf, p, len); - if( n != 1 ) - ShowDebug("parse_simpleexpr: unexpected length %d after unescape (\"%.*s\" -> %.*s)\n", (int)n, (int)len, p, (int)n, buf); - p += len; - script->addb(*buf); - continue; - } else if( *p == '\n' ) { - disp_error_message("parse_simpleexpr: unexpected newline @ string",p); + do { + p++; + while( *p && *p != '"' ) { + if( (unsigned char)p[-1] <= 0x7e && *p == '\\' ) { + char buf[8]; + size_t len = sv->skip_escaped_c(p) - p; + size_t n = sv->unescape_c(buf, p, len); + if( n != 1 ) + ShowDebug("parse_simpleexpr: unexpected length %d after unescape (\"%.*s\" -> %.*s)\n", (int)n, (int)len, p, (int)n, buf); + p += len; + script->addb(*buf); + continue; + } else if( *p == '\n' ) { + disp_error_message("parse_simpleexpr: unexpected newline @ string",p); + } + script->addb(*p++); } - script->addb(*p++); - } - if(!*p) - disp_error_message("parse_simpleexpr: unexpected end of file @ string",p); + if(!*p) + disp_error_message("parse_simpleexpr: unexpected end of file @ string",p); + p++; //'"' + p = script->skip_space(p); + } while( *p && *p == '"' ); script->addb(0); - p++; //'"' } else { int l; const char* pv; |