added amb1610 - StripQuotes()
--HG-- branch : sourcemod-1.0.x extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/branches/sourcemod-1.0.x%402064
This commit is contained in:
parent
b51b34fbf4
commit
40046d8248
@ -2,7 +2,7 @@
|
||||
* vim: set ts=4 :
|
||||
* =============================================================================
|
||||
* SourceMod
|
||||
* Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
|
||||
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
||||
* =============================================================================
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
@ -560,6 +560,27 @@ static cell_t SplitString(IPluginContext *pContext, const cell_t *params)
|
||||
return -1;
|
||||
}
|
||||
|
||||
static cell_t StripQuotes(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
char *text;
|
||||
size_t length;
|
||||
|
||||
pContext->LocalToString(params[1], &text);
|
||||
length = strlen(text);
|
||||
|
||||
if (text[0] == '"' && text[length-1] == '"')
|
||||
{
|
||||
/* Null-terminate */
|
||||
text[--length] = '\0';
|
||||
/* Move the remaining bytes (including null terminator) down by one */
|
||||
memmove(&text[0], &text[1], length);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
REGISTER_NATIVES(basicStrings)
|
||||
{
|
||||
{"BreakString", BreakString},
|
||||
@ -586,6 +607,7 @@ REGISTER_NATIVES(basicStrings)
|
||||
{"StringToIntEx", StringToIntEx},
|
||||
{"StringToFloat", sm_strtofloat},
|
||||
{"StringToFloatEx", StringToFloatEx},
|
||||
{"StripQuotes", StripQuotes},
|
||||
{"TrimString", TrimString},
|
||||
{"VFormat", sm_vformat},
|
||||
{NULL, NULL},
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* vim: set ts=4 :
|
||||
* =============================================================================
|
||||
* SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
|
||||
* SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
|
||||
* =============================================================================
|
||||
*
|
||||
* This file is part of the SourceMod/SourcePawn SDK.
|
||||
@ -375,6 +375,20 @@ native bool:IsCharUpper(chr);
|
||||
*/
|
||||
native bool:IsCharLower(chr);
|
||||
|
||||
/**
|
||||
* Strips a quote pair off a string if it exists. That is, the following
|
||||
* replace rule is applied once: $"(.*)"^ -> $\1^
|
||||
*
|
||||
* Note that the leading and trailing quotes will only be removed if both
|
||||
* exist. Otherwise, the string is left unmodified. This function should
|
||||
* be considered O(k) (all characters get shifted down).
|
||||
*
|
||||
* @param text String to modify (in place).
|
||||
* @return True if string was modified, false if there was no
|
||||
* set of quotes.
|
||||
*/
|
||||
native bool:StripQuotes(String:text[]);
|
||||
|
||||
/**
|
||||
* Returns an uppercase character to a lowercase character.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user