Browse Source

base: fix PS3 build and use C library functions in string.h when possible.

legacy
Sam Hocevar sam 11 years ago
parent
commit
fa31f691f9
1 changed files with 13 additions and 27 deletions
  1. +13
    -27
      src/lol/base/string.h

+ 13
- 27
src/lol/base/string.h View File

@@ -119,46 +119,32 @@ public:


int IndexOf(const char token) const int IndexOf(const char token) const
{ {
for (int i = 0; i < Count(); ++i)
{
if ((*this)[i] == token)
return i;
}
return -1;
using namespace std;

char *tmp = strchr(C(), token);
return tmp ? (int)(intptr_t)(tmp - C()) : -1;
} }


int IndexOf(const char* token) const int IndexOf(const char* token) const
{ {
int token_len = strlen(token);
if (Count() < token_len)
return -1;
using namespace std;


for (int i = 0; i < Count() - token_len + 1; ++i)
{
int j = 0;
for (; j < token_len; ++j)
{
if ((*this)[i + j] != token[j])
break;
}
if (j == token_len)
return i;
}
return -1;
char *tmp = strstr(C(), token);
return tmp ? (int)(intptr_t)(tmp - C()) : -1;
} }


int LastIndexOf(const char token) const int LastIndexOf(const char token) const
{ {
for (int i = Count() - 1; i >= 0; --i)
{
if ((*this)[i] == token)
return i;
}
return -1;
using namespace std;

char *tmp = strrchr(C(), token);
return tmp ? (int)(intptr_t)(tmp - C()) : -1;
} }


int LastIndexOf(const char* token) const int LastIndexOf(const char* token) const
{ {
using namespace std;

int token_len = strlen(token); int token_len = strlen(token);
if (Count() < token_len) if (Count() < token_len)
return -1; return -1;


Loading…
Cancel
Save