diff --git a/src/game/Chat.cpp b/src/game/Chat.cpp index 16afd830d..f8917fe64 100644 --- a/src/game/Chat.cpp +++ b/src/game/Chat.cpp @@ -2261,9 +2261,10 @@ char* ChatHandler::ExtractLiteralArg(char** args, char const* lit /*= NULL*/) * Function extract quote-like string (any characters guarded by some special character, in our cases ['") * * @param args variable pointer to non parsed args string, updated at function call to new position (with skipped white spaces) + * @param asis control save quote string wrappers * @return quote-like string, or NULL if args empty or not appropriate content. */ -char* ChatHandler::ExtractQuotedArg( char** args ) +char* ChatHandler::ExtractQuotedArg( char** args, bool asis /*= false*/ ) { if (!*args || !**args) return NULL; @@ -2271,32 +2272,50 @@ char* ChatHandler::ExtractQuotedArg( char** args ) if (**args != '\'' && **args != '"' && **args != '[') return NULL; - char guard[2] = " "; // guard[1] == '\0' + char guard = (*args)[0]; - guard[0] = (*args)[0]; + if (guard == '[') + guard = ']'; - if (guard[0] == '[') - guard[0] = ']'; + char* tail = (*args)+1; // start scan after first quote symbol + char* head = asis ? *args : tail; // start arg - char* str = strtok((*args)+1, guard); // skip start guard symbol + while (*tail && *tail != guard) + ++tail; - char* tail = strtok(NULL, ""); - *args = tail ? tail : (char*)""; // *args don't must be NULL + if (!*tail || tail[1] && !isWhiteSpace(tail[1])) // fail + return NULL; + + if (!tail[1]) // quote is last char in string + { + if (!asis) + *tail = '\0'; + } + else // quote isn't last char + { + if (asis) + ++tail; + + *tail = '\0'; + } + + *args = tail+1; SkipWhiteSpaces(args); - return str; + return head; } /** * Function extract quote-like string or literal if quote not detected * * @param args variable pointer to non parsed args string, updated at function call to new position (with skipped white spaces) + * @param asis control save quote string wrappers * @return quote/literal string, or NULL if args empty or not appropriate content. */ -char* ChatHandler::ExtractQuotedOrLiteralArg(char** args) +char* ChatHandler::ExtractQuotedOrLiteralArg(char** args, bool asis /*= false*/) { - char *arg = ExtractQuotedArg(args); + char *arg = ExtractQuotedArg(args, asis); if (!arg) arg = ExtractLiteralArg(args); return arg; @@ -2518,14 +2537,15 @@ char* ChatHandler::ExtractLinkArg(char** args, char const* const* linkTypes /*= * Function extract name/number/quote/shift-link-like string * * @param args variable pointer to non parsed args string, updated at function call to new position (with skipped white spaces) + * @param asis control save quote string wrappers * @return extracted arg string, or NULL if args empty or not appropriate content. */ -char* ChatHandler::ExtractArg( char** args ) +char* ChatHandler::ExtractArg( char** args, bool asis /*= false*/ ) { if (!*args || !**args) return NULL; - char* arg = ExtractQuotedOrLiteralArg(args); + char* arg = ExtractQuotedOrLiteralArg(args, asis); if (!arg) arg = ExtractLinkArg(args); @@ -2541,7 +2561,7 @@ char* ChatHandler::ExtractArg( char** args ) */ char* ChatHandler::ExtractOptNotLastArg(char** args) { - char* arg = ExtractArg(args); + char* arg = ExtractArg(args, true); // have more data if (*args && **args) diff --git a/src/game/Chat.h b/src/game/Chat.h index f1a6e17eb..2a3073e47 100644 --- a/src/game/Chat.h +++ b/src/game/Chat.h @@ -572,14 +572,15 @@ class ChatHandler bool ExtractOptUInt32(char** args, uint32& val, uint32 defVal); bool ExtractFloat(char** args, float& val); bool ExtractOptFloat(char** args, float& val, float defVal); - char* ExtractQuotedArg(char** args); // string with " or [] or ' around + char* ExtractQuotedArg(char** args, bool asis = false); + // string with " or [] or ' around char* ExtractLiteralArg(char** args, char const* lit = NULL); // literal string (until whitespace and not started from "['|), any or 'lit' if provided - char* ExtractQuotedOrLiteralArg(char** args); + char* ExtractQuotedOrLiteralArg(char** args, bool asis = false); bool ExtractOnOff(char** args, bool& value); char* ExtractLinkArg(char** args, char const* const* linkTypes = NULL, int* foundIdx = NULL, char** keyPair = NULL, char** somethingPair = NULL); // shift-link like arg (with aditional info if need) - char* ExtractArg(char** args); // any name/number/quote/shift-link strings + char* ExtractArg(char** args, bool asis = false); // any name/number/quote/shift-link strings char* ExtractOptNotLastArg(char** args); // extract name/number/quote/shift-link arg only if more data in args for parse char* ExtractKeyFromLink(char** text, char const* linkType, char** something1 = NULL); diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index 97a0c1906..8671cade6 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "10386" + #define REVISION_NR "10387" #endif // __REVISION_NR_H__