Browse Source

Merge pull request #3 from dpogue/string_cleaning

String cleaning
Adam Johnson 10 years ago
parent
commit
dde82a9603
  1. 13
      Sources/Plasma/NucleusLib/pnUtils/CMakeLists.txt
  2. 61
      Sources/Plasma/NucleusLib/pnUtils/Unix/pnUtUxStr.cpp
  3. 148
      Sources/Plasma/NucleusLib/pnUtils/pnUtStr.cpp
  4. 15
      Sources/Plasma/NucleusLib/pnUtils/pnUtStr.h

13
Sources/Plasma/NucleusLib/pnUtils/CMakeLists.txt

@ -34,19 +34,12 @@ if(WIN32)
set(pnUtils_WIN32
Win32/pnUtW32Misc.cpp
)
else()
set(pnUtils_UNIX
Unix/pnUtUxStr.cpp
)
endif()
endif(WIN32)
add_library(pnUtils STATIC ${pnUtils_HEADERS} ${pnUtils_SOURCES}
${pnUtils_UNIX} ${pnUtils_WIN32})
add_library(pnUtils STATIC ${pnUtils_HEADERS} ${pnUtils_SOURCES} ${pnUtils_WIN32})
source_group("Header Files" FILES ${pnUtils_HEADERS})
source_group("Source Files" FILES ${pnUtils_SOURCES})
if(WIN32)
source_group("Win32" FILES ${pnUtils_WIN32})
else()
source_group("Unix" FILES ${pnUtils_UNIX})
endif()
endif(WIN32)

61
Sources/Plasma/NucleusLib/pnUtils/Unix/pnUtUxStr.cpp

@ -1,61 +0,0 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/NucleusLib/pnUtils/Private/Unix/pnUtUxStr.cpp
*
***/
#include "../pnUtStr.h"
#ifdef HS_BUILD_FOR_UNIX
#else
// Dummy function to prevent a linker warning complaining about no public symbols if the
// contents of the file get compiled out via pre-processor
void UxStrPreventLNK4221Warning () {
}
#endif

148
Sources/Plasma/NucleusLib/pnUtils/pnUtStr.cpp

@ -98,17 +98,6 @@ static chartype * IStrDup (const chartype str[]) {
return buffer;
}
//===========================================================================
template<class chartype>
static chartype * IStrDupLen (const chartype str[], unsigned chars) {
unsigned len = IStrLen(str) + 1;
if (len > chars)
len = chars;
chartype * buffer = (chartype *)malloc(len * sizeof(chartype));
IStrCopy(buffer, str, len);
return buffer;
}
//===========================================================================
template<class chartype, class findchartype>
static chartype * IStrChr (chartype * str, findchartype ch, unsigned chars) {
@ -120,60 +109,6 @@ static chartype * IStrChr (chartype * str, findchartype ch, unsigned chars) {
return nil;
}
//===========================================================================
static inline bool ICharUnicodeToUtf8 (char ** dest, const wchar_t * source[], unsigned destChars) {
unsigned ch = *(*source)++;
bool result = false;
if (ch < 0x80) {
if (destChars >= 1) {
*(*dest)++ = (char)ch;
result = true;
}
}
else if (ch < 0x800) {
if (destChars >= 2) {
*(*dest)++ = (char)(0xc0 | (ch >> 6));
*(*dest)++ = (char)(0x80 | (ch & 0x3f));
result = true;
}
}
else {
if (destChars >= 3) {
*(*dest)++ = (char)(0xe0 | (ch >> 12));
*(*dest)++ = (char)(0x80 | ((ch >> 6) & 0x3f));
*(*dest)++ = (char)(0x80 | (ch & 0x3f));
result = true;
}
}
return result;
}
//===========================================================================
static inline void ICharUtf8ToUnicode (wchar_t ** dest, const char * source[]) {
unsigned result, remaining;
if ((**source & 0xf0) == 0xe0) {
result = *(*source)++ & 0x0f;
remaining = 2;
}
else if ((**source & 0xe0) == 0xc0) {
result = *(*source)++ & 0x1f;
remaining = 1;
}
else if ((**source & 0x80) == 0x00) {
result = *(*source)++;
remaining = 0;
}
else {
// unsupported code sequence (>0xffff)
++(*source);
return;
}
for (; remaining-- && *source; ++*source)
if ((**source & 0xc0) == 0x80)
result = (result << 6) | (**source & 0x3f);
*(*dest)++ = (wchar_t)result;
}
//===========================================================================
template<typename chartype>
static unsigned IStrPrintfValidate (chartype * dest, unsigned count, int result) {
@ -214,39 +149,6 @@ static int IStrCmpI (const chartype str1[], const chartype str2[], unsigned char
return 0;
}
//===========================================================================
template<class chartype>
static void IStrPack (chartype * dest, const chartype source[], unsigned chars) {
while ((chars > 1) && *dest) {
--chars;
++dest;
}
while ((chars > 1) && ((*dest = *source++) != 0)) {
--chars;
++dest;
}
if (chars)
*dest = 0;
}
//===========================================================================
template<class chartype>
static chartype * IStrStr (chartype source[], const chartype match[]) {
if (!*match)
return source;
for (chartype * curr = source; *curr; ++curr) {
chartype * s1 = curr;
const chartype * s2 = match;
while (*s1 && *s2 && *s1 == *s2)
s1++, s2++;
if (!*s2)
return curr;
}
return nil;
}
//===========================================================================
template<class chartype>
static uint32_t IStrHash (const chartype str[], unsigned chars) {
@ -374,26 +276,6 @@ wchar_t * StrDup (const wchar_t str[]) {
return IStrDup(str);
}
//===========================================================================
char * StrDupLen (const char str[], unsigned chars) {
return IStrDupLen(str, chars);
}
//===========================================================================
wchar_t * StrDupLen (const wchar_t str[], unsigned chars) {
return IStrDupLen(str, chars);
}
//===========================================================================
unsigned StrBytes (const char str[]) { // includes space for terminator
return (IStrLen(str) + 1) * sizeof(str[0]);
}
//===========================================================================
unsigned StrBytes (const wchar_t str[]) { // includes space for terminator
return (IStrLen(str) + 1) * sizeof(str[0]);
}
//===========================================================================
char * StrChr (char * str, char ch, unsigned chars) {
return IStrChr(str, ch, chars);
@ -474,36 +356,6 @@ void StrCopy (wchar_t * dest, const wchar_t source[], unsigned chars) {
IStrCopy(dest, source, chars);
}
//===========================================================================
void StrPack (char * dest, const char source[], unsigned chars) {
IStrPack(dest, source, chars);
}
//===========================================================================
void StrPack (wchar_t * dest, const wchar_t source[], unsigned chars) {
IStrPack(dest, source, chars);
}
//===========================================================================
char * StrStr (char * source, const char match[]) {
return IStrStr(source, match);
}
//===========================================================================
const char * StrStr (const char source[], const char match[]) {
return IStrStr<const char>(source, match);
}
//===========================================================================
wchar_t * StrStr (wchar_t * source, const wchar_t match[]) {
return IStrStr(source, match);
}
//===========================================================================
const wchar_t * StrStr (const wchar_t source[], const wchar_t match[]) {
return IStrStr<const wchar_t>(source, match);
}
//===========================================================================
unsigned StrLen (const char str[]) {
return IStrLen(str);

15
Sources/Plasma/NucleusLib/pnUtils/pnUtStr.h

@ -57,7 +57,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#ifdef _INC_SHLWAPI
# undef StrChr
# undef StrDup
# undef StrStr
#endif // _INC_SHLWAPI
/*****************************************************************************
@ -69,9 +68,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
inline char CharLowerFast (char ch) { return ((ch >= 'A') && (ch <= 'Z')) ? (char )(ch + 'a' - 'A') : ch; }
inline wchar_t CharLowerFast (wchar_t ch) { return ((ch >= L'A') && (ch <= L'Z')) ? (wchar_t)(ch + L'a' - L'A') : ch; }
unsigned StrBytes (const char str[]); // includes space for terminator
unsigned StrBytes (const wchar_t str[]); // includes space for terminator
char * StrChr (char * str, char ch, unsigned chars = (unsigned)-1);
wchar_t * StrChr (wchar_t * str, wchar_t ch, unsigned chars = (unsigned)-1);
const char * StrChr (const char str[], char ch, unsigned chars = (unsigned)-1);
@ -89,26 +85,15 @@ unsigned StrLen (const wchar_t str[]);
char * StrDup (const char str[]);
wchar_t * StrDup (const wchar_t str[]);
char * StrDupLen (const char str[], unsigned chars);
wchar_t * StrDupLen (const wchar_t str[], unsigned chars);
int StrCmp (const char str1[], const char str2[], unsigned chars = (unsigned)-1);
int StrCmp (const wchar_t str1[], const wchar_t str2[], unsigned chars = (unsigned)-1);
int StrCmpI (const char str1[], const char str2[], unsigned chars = (unsigned)-1);
int StrCmpI (const wchar_t str1[], const wchar_t str2[], unsigned chars = (unsigned)-1);
char * StrStr (char * source, const char match[]);
const char * StrStr (const char source[], const char match[]);
wchar_t * StrStr (wchar_t * source, const wchar_t match[]);
const wchar_t * StrStr (const wchar_t source[], const wchar_t match[]);
void StrCopy (char * dest, const char source[], unsigned chars);
void StrCopy (wchar_t * dest, const wchar_t source[], unsigned chars);
void StrPack (char * dest, const char source[], unsigned chars);
void StrPack (wchar_t * dest, const wchar_t source[], unsigned chars);
float StrToFloat (const char source[], const char ** endptr);
float StrToFloat (const wchar_t source[], const wchar_t ** endptr);

Loading…
Cancel
Save