From 49a4613d94d8e500e5bd3c259693fb5ccec4612e Mon Sep 17 00:00:00 2001 From: faketruth Date: Wed, 22 Aug 2012 23:05:12 +0000 Subject: Added a RateCompareString function to StringUtils Created a preprocessor template (define) for DoWith* functions Exported cWorld::FindAndDoWithPlayer(), cRoot::FindAndDoWithPlayer() and cRoot::ForEachPlayer() to Lua Added a function FindAndDoWithPlayer to cRoot and cWorld. It takes a part of a player name and finds a single player based on that. Fixed Core's MOTD to contain the correct URL to the MCServer site Fixed Core /kick command Fixed Core's WebAdmin kick git-svn-id: http://mc-server.googlecode.com/svn/trunk@779 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/StringUtils.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'source/StringUtils.cpp') diff --git a/source/StringUtils.cpp b/source/StringUtils.cpp index ccdbe687a..e3eb95a6e 100644 --- a/source/StringUtils.cpp +++ b/source/StringUtils.cpp @@ -172,6 +172,33 @@ int NoCaseCompare(const AString & s1, const AString & s2) +unsigned int RateCompareString(const AString & s1, const AString & s2 ) +{ + unsigned int MatchedLetters = 0; + unsigned int s1Length = s1.length(); + + if( s1Length > s2.length() ) return 0; // Definitely not a match + + for (unsigned int i = 0; i < s1Length; i++) + { + char c1 = (char)toupper( s1[i] ); + char c2 = (char)toupper( s2[i] ); + if( c1 == c2 ) + { + ++MatchedLetters; + } + else + { + break; + } + } + return MatchedLetters; +} + + + + + void ReplaceString(AString & iHayStack, const AString & iNeedle, const AString & iReplaceWith) { size_t pos1 = iHayStack.find(iNeedle); -- cgit v1.2.3