added amb1610 - StripQuotes()
authorDavid Anderson <dvander@alliedmods.net>
Wed Apr 16 05:27:09 2008 +0000 (2008-04-16)
changeset 2004c9f1dc4cdaed
parent 2003 2b6cd7cd82e3
child 2005 92033efef85f
added amb1610 - StripQuotes()
core/smn_string.cpp
plugins/include/string.inc
     1.1 --- a/core/smn_string.cpp	Wed Apr 16 05:04:33 2008 +0000
     1.2 +++ b/core/smn_string.cpp	Wed Apr 16 05:27:09 2008 +0000
     1.3 @@ -560,6 +560,27 @@
     1.4  	return -1;
     1.5  }
     1.6  
     1.7 +static cell_t StripQuotes(IPluginContext *pContext, const cell_t *params)
     1.8 +{
     1.9 +	char *text;
    1.10 +	size_t length;
    1.11 +
    1.12 +	pContext->LocalToString(params[1], &text);
    1.13 +	length = strlen(text);
    1.14 +
    1.15 +	if (text[0] == '"' && text[length-1] == '"')
    1.16 +	{
    1.17 +		/* Null-terminate */
    1.18 +		text[--length] = '\0';
    1.19 +		/* Move the remaining bytes (including null terminator) down by one */
    1.20 +		memmove(&text[0], &text[1], length);
    1.21 +
    1.22 +		return 1;
    1.23 +	}
    1.24 +
    1.25 +	return 0;	
    1.26 +}
    1.27 +
    1.28  REGISTER_NATIVES(basicStrings)
    1.29  {
    1.30  	{"BreakString",			BreakString},
    1.31 @@ -586,6 +607,7 @@
    1.32  	{"StringToIntEx",		StringToIntEx},
    1.33  	{"StringToFloat",		sm_strtofloat},
    1.34  	{"StringToFloatEx",		StringToFloatEx},
    1.35 +	{"StripQuotes",			StripQuotes},
    1.36  	{"TrimString",			TrimString},
    1.37  	{"VFormat",				sm_vformat},
    1.38  	{NULL,					NULL},
     2.1 --- a/plugins/include/string.inc	Wed Apr 16 05:04:33 2008 +0000
     2.2 +++ b/plugins/include/string.inc	Wed Apr 16 05:27:09 2008 +0000
     2.3 @@ -376,6 +376,20 @@
     2.4  native bool:IsCharLower(chr);
     2.5  
     2.6  /**
     2.7 + * Strips a quote pair off a string if it exists.  That is, the following 
     2.8 + * replace rule is applied once:  $"(.*)"^ -> $\1^
     2.9 + *
    2.10 + * Note that the leading and trailing quotes will only be removed if both 
    2.11 + * exist.  Otherwise, the string is left unmodified.  This function should 
    2.12 + * be considered O(k) (all characters get shifted down).
    2.13 + *
    2.14 + * @param text			String to modify (in place).
    2.15 + * @return				True if string was modified, false if there was no 
    2.16 + *						set of quotes.
    2.17 + */
    2.18 +native bool:StripQuotes(String:text[]);
    2.19 +
    2.20 +/**
    2.21   * Returns an uppercase character to a lowercase character.
    2.22   *
    2.23   * @param chr			Characer to convert.