Subversion Repositories WoWGM

Rev

Rev 18 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

#include "../H/STPL.h"


/****************************************************************************
*
*       Private functions
*
***/

//===========================================================================
int ToLower(int ch)
{
        if (ch > 64 && ch < 91)
                ch+=32;
        return ch;
}

//===========================================================================
int ToUpper(int ch)
{
        if (ch > 96 && ch < 123)
                ch-=32;
        return ch;
}


/****************************************************************************
*
*       External functions
*
***/

//===========================================================================
char const* SStrChr(char const* string, char ch)
{
        // TODO: ASSERT(string);
        if (*string == 0)
                return 0;
        char const* copy = string;
        char currChar = *string;
        while (currChar != ch) {
                currChar = *++copy;
                if (currChar == 0)
                        return 0;
        }
        return copy;
}

//===========================================================================
char* SStrChr(char* string, char ch)
{
        // TODO: ASSERT(string);
        if (*string == 0)
                return 0;
        char* copy = string;
        char currChar = *string;
        while (currChar != ch) {
                currChar = *++copy;
                if (currChar == 0)
                        return 0;
        }
        return copy;
}

//===========================================================================
extern char const* SStrChrR(char const* string, char ch)
{
        return 0;
}

//===========================================================================
extern char* SStrChrR(char* string, char ch)
{
        return 0;
}

//===========================================================================
extern DWORD SStrCopy(char* dest, char const* source, DWORD destsize)
{
        // TODO: ASSERT(dest);
        // TODO: ASSERT(source);
        for (DWORD length = 0; length < destsize; length++)
        {
                dest[length] = source[length];
                if (source[length] == '\0')
                        return length;
        }
        return 0;
}

//===========================================================================
extern int SStrCmp(char const* string1, char const* string2, DWORD maxchars)
{
        // TODO: ASSERT(string1);
        // TODO: ASSERT(string2);
        return 0;
}

//===========================================================================
extern int SStrCmpI(char const* string1, char const* string2, DWORD maxchars)
{
        // TODO: ASSERT(string1);
        // TODO: ASSERT(string2);
        return 0;
}

//===========================================================================
inline DWORD SStrLen(char const* string)
{
        // TODO: ASSERT(string);

        char const* i;
        for (i = string; *i; ++i);
        return static_cast<DWORD>(i - string);
}

//===========================================================================
inline DWORD SStrLen(unsigned short const* string)
{
        // TODO: ASSERT(string);

        unsigned short const* i;
        for (i = string; *i; ++i);
        return static_cast<DWORD>(i - string);
}

//===========================================================================
void SStrLower(char* string)
{
        // TODO: ASSERT(string);
        while(*string)
        {
                *string = ToLower(*string);
                ++string;
        }
}

//===========================================================================
int SStrToInt(char const* string)
{
        char const* copy = string;
        // TODO: ASSERT(string);
        if (*string == '-') {
                copy = string + 1;
        }
        int result = *copy - 48;
        if (result >= 10) {
                result = 0;
        }
        else
        {
                char const* next = (copy + 1);
                for (int i = copy[1] - 48; i < 10 && i >= 0; i = *next - 48 )
                {
                        ++next;
                        result = i + 10 * result;
                }
        }
        if ( *string == '-' )
        {
                return -result;
        }
        return result;
}

//===========================================================================
void SStrUpper(char* string)
{
        // TODO: ASSERT(string);
        while(*string)
        {
                *string = ToUpper(*string);
                ++string;
        }
}