1
0

Added StringUtils functions to Lua API; added StripColorCodes(); ChatLog now strips color codes from logged messages.

Fixes FS #398

git-svn-id: http://mc-server.googlecode.com/svn/trunk@1661 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
madmaxoft@gmail.com 2013-07-07 14:42:07 +00:00
parent 0224a4f7fc
commit 5951bc76ec
6 changed files with 196 additions and 9 deletions

View File

@ -26,7 +26,7 @@ end
function OnChat(Player, Message)
-- Lets get loggin'
LOGINFO("[" .. Player:GetName() .. "]: " .. Message);
LOGINFO("[" .. Player:GetName() .. "]: " .. StripColorCodes(Message));
return false
end

View File

@ -18,6 +18,7 @@ $cfile "ChunkDef.h"
$cfile "../iniFile/iniFile.h"
$cfile "BlockID.h"
$cfile "StringUtils.h"
$cfile "Defines.h"
$cfile "LuaFunctions.h"
$cfile "StringMap.h"

View File

@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
** Generated automatically by tolua++-1.0.92 on 07/07/13 15:41:32.
** Generated automatically by tolua++-1.0.92 on 07/07/13 16:40:05.
*/
#ifndef __cplusplus
@ -18,6 +18,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S);
#include "ChunkDef.h"
#include "../iniFile/iniFile.h"
#include "BlockID.h"
#include "StringUtils.h"
#include "Defines.h"
#include "LuaFunctions.h"
#include "StringMap.h"
@ -2649,6 +2650,164 @@ static int tolua_AllToLua_StringToDamageType00(lua_State* tolua_S)
}
#endif //#ifndef TOLUA_DISABLE
/* function: TrimString */
#ifndef TOLUA_DISABLE_tolua_AllToLua_TrimString00
static int tolua_AllToLua_TrimString00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_iscppstring(tolua_S,1,0,&tolua_err) ||
!tolua_isnoobj(tolua_S,2,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
const AString str = ((const AString) tolua_tocppstring(tolua_S,1,0));
{
AString tolua_ret = (AString) TrimString(str);
tolua_pushcppstring(tolua_S,(const char*)tolua_ret);
tolua_pushcppstring(tolua_S,(const char*)str);
}
}
return 2;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'TrimString'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE
/* function: NoCaseCompare */
#ifndef TOLUA_DISABLE_tolua_AllToLua_NoCaseCompare00
static int tolua_AllToLua_NoCaseCompare00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_iscppstring(tolua_S,1,0,&tolua_err) ||
!tolua_iscppstring(tolua_S,2,0,&tolua_err) ||
!tolua_isnoobj(tolua_S,3,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
const AString s1 = ((const AString) tolua_tocppstring(tolua_S,1,0));
const AString s2 = ((const AString) tolua_tocppstring(tolua_S,2,0));
{
int tolua_ret = (int) NoCaseCompare(s1,s2);
tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
tolua_pushcppstring(tolua_S,(const char*)s1);
tolua_pushcppstring(tolua_S,(const char*)s2);
}
}
return 3;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'NoCaseCompare'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE
/* function: ReplaceString */
#ifndef TOLUA_DISABLE_tolua_AllToLua_ReplaceString00
static int tolua_AllToLua_ReplaceString00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_iscppstring(tolua_S,1,0,&tolua_err) ||
!tolua_iscppstring(tolua_S,2,0,&tolua_err) ||
!tolua_iscppstring(tolua_S,3,0,&tolua_err) ||
!tolua_isnoobj(tolua_S,4,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
AString iHayStack = ((AString) tolua_tocppstring(tolua_S,1,0));
const AString iNeedle = ((const AString) tolua_tocppstring(tolua_S,2,0));
const AString iReplaceWith = ((const AString) tolua_tocppstring(tolua_S,3,0));
{
ReplaceString(iHayStack,iNeedle,iReplaceWith);
tolua_pushcppstring(tolua_S,(const char*)iHayStack);
tolua_pushcppstring(tolua_S,(const char*)iNeedle);
tolua_pushcppstring(tolua_S,(const char*)iReplaceWith);
}
}
return 3;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'ReplaceString'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE
/* function: EscapeString */
#ifndef TOLUA_DISABLE_tolua_AllToLua_EscapeString00
static int tolua_AllToLua_EscapeString00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_iscppstring(tolua_S,1,0,&tolua_err) ||
!tolua_isnoobj(tolua_S,2,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
const AString a_Message = ((const AString) tolua_tocppstring(tolua_S,1,0));
{
AString tolua_ret = (AString) EscapeString(a_Message);
tolua_pushcppstring(tolua_S,(const char*)tolua_ret);
tolua_pushcppstring(tolua_S,(const char*)a_Message);
}
}
return 2;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'EscapeString'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE
/* function: StripColorCodes */
#ifndef TOLUA_DISABLE_tolua_AllToLua_StripColorCodes00
static int tolua_AllToLua_StripColorCodes00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_iscppstring(tolua_S,1,0,&tolua_err) ||
!tolua_isnoobj(tolua_S,2,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
const AString a_Message = ((const AString) tolua_tocppstring(tolua_S,1,0));
{
AString tolua_ret = (AString) StripColorCodes(a_Message);
tolua_pushcppstring(tolua_S,(const char*)tolua_ret);
tolua_pushcppstring(tolua_S,(const char*)a_Message);
}
}
return 2;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'StripColorCodes'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE
/* get function: g_BlockLightValue */
#ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockLightValue
static int tolua_get_AllToLua_g_BlockLightValue(lua_State* tolua_S)
@ -28119,6 +28278,11 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_function(tolua_S,"StringToDimension",tolua_AllToLua_StringToDimension00);
tolua_function(tolua_S,"DamageTypeToString",tolua_AllToLua_DamageTypeToString00);
tolua_function(tolua_S,"StringToDamageType",tolua_AllToLua_StringToDamageType00);
tolua_function(tolua_S,"TrimString",tolua_AllToLua_TrimString00);
tolua_function(tolua_S,"NoCaseCompare",tolua_AllToLua_NoCaseCompare00);
tolua_function(tolua_S,"ReplaceString",tolua_AllToLua_ReplaceString00);
tolua_function(tolua_S,"EscapeString",tolua_AllToLua_EscapeString00);
tolua_function(tolua_S,"StripColorCodes",tolua_AllToLua_StripColorCodes00);
tolua_array(tolua_S,"g_BlockLightValue",tolua_get_AllToLua_g_BlockLightValue,tolua_set_AllToLua_g_BlockLightValue);
tolua_array(tolua_S,"g_BlockSpreadLightFalloff",tolua_get_AllToLua_g_BlockSpreadLightFalloff,tolua_set_AllToLua_g_BlockSpreadLightFalloff);
tolua_array(tolua_S,"g_BlockTransparent",tolua_get_AllToLua_g_BlockTransparent,tolua_set_AllToLua_g_BlockTransparent);

View File

@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
** Generated automatically by tolua++-1.0.92 on 07/07/13 15:41:32.
** Generated automatically by tolua++-1.0.92 on 07/07/13 16:40:06.
*/
/* Exported function */

View File

@ -594,8 +594,8 @@ AString EscapeString(const AString & a_Message)
last = i + 1;
break;
}
}
}
} // switch (ch)
} // for i - a_Message[]
if (len > last)
{
EscapedMsg.append(a_Message, last, len - last);
@ -606,3 +606,22 @@ AString EscapeString(const AString & a_Message)
AString StripColorCodes(const AString & a_Message)
{
AString res(a_Message);
size_t idx = 0;
while (true)
{
idx = res.find("\xc2\xa7", idx);
if (idx == AString::npos)
{
return res;
}
res.erase(idx, 3);
}
}

View File

@ -40,19 +40,19 @@ extern AStringVector StringSplit(const AString & str, const AString & delim);
extern AStringVector StringSplitAndTrim(const AString & str, const AString & delim);
/// Trime whitespace at both ends of the string
extern AString TrimString(const AString & str);
extern AString TrimString(const AString & str); // tolua_export
/// In-place string conversion to uppercase; returns the same string
extern AString & StrToUpper(AString & s);
/// Case-insensitive string comparison; returns 0 if the strings are the same
extern int NoCaseCompare(const AString & s1, const AString & s2);
extern int NoCaseCompare(const AString & s1, const AString & s2); // tolua_export
/// Case-insensitive string comparison that returns a rating of equal-ness between [0 - s1.length()]
extern unsigned int RateCompareString(const AString & s1, const AString & s2 );
/// Replaces *each* occurence of iNeedle in iHayStack with iReplaceWith
extern void ReplaceString(AString & iHayStack, const AString & iNeedle, const AString & iReplaceWith);
extern void ReplaceString(AString & iHayStack, const AString & iNeedle, const AString & iReplaceWith); // tolua_export
/// Returns the list of all items in the specified directory (files, folders, nix pipes, whatever's there)
extern AStringList GetDirectoryContents(const char * a_Directory);
@ -67,7 +67,10 @@ extern AString & UTF8ToRawBEUTF16(const char * a_UTF8, size_t a_UTF8Length, AStr
extern AString & CreateHexDump(AString & a_Out, const void * a_Data, int a_Size, int a_BytesPerLine);
/// Returns a copy of a_Message with all quotes and backslashes escaped by a backslash
extern AString EscapeString(const AString & a_Message);
extern AString EscapeString(const AString & a_Message); // tolua_export
/// Removes all control codes used by MC for colors and styles
extern AString StripColorCodes(const AString & a_Message); // tolua_export
// If you have any other string helper functions, declare them here