X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/b37bf2e156556c589aea3e1f58a377f2b1189665..b80e619319b1def83d1e8b4f84042b661be1be7f:/wtf/StringExtras.h diff --git a/wtf/StringExtras.h b/wtf/StringExtras.h index ca1c20c..28e80b8 100644 --- a/wtf/StringExtras.h +++ b/wtf/StringExtras.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. + * Copyright (C) 2006 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,27 +26,87 @@ #ifndef WTF_StringExtras_h #define WTF_StringExtras_h -#include #include +#include + +#if HAVE(STRINGS_H) +#include +#endif #if COMPILER(MSVC) +// FIXME: why a COMPILER check instead of OS? also, these should be HAVE checks -inline int snprintf(char *str, size_t size, const char* format, ...) +inline int snprintf(char* buffer, size_t count, const char* format, ...) { int result; va_list args; va_start(args, format); - result = _vsnprintf(str, size, format, args); + result = _vsnprintf(buffer, count, format, args); va_end(args); return result; } -#if COMPILER(MSVC7) -// MSVC8 and above define this function -#define vsnprintf snprintf +#if COMPILER(MSVC7_OR_LOWER) || OS(WINCE) + +inline int vsnprintf(char* buffer, size_t count, const char* format, va_list args) +{ + return _vsnprintf(buffer, count, format, args); +} + +#endif + +#if OS(WINCE) + +inline int strnicmp(const char* string1, const char* string2, size_t count) +{ + return _strnicmp(string1, string2, count); +} + +inline int stricmp(const char* string1, const char* string2) +{ + return _stricmp(string1, string2); +} + +inline char* strdup(const char* strSource) +{ + return _strdup(strSource); +} + #endif -inline int strncasecmp(const char* s1, const char* s2, size_t len) { return strnicmp(s1, s2, len); } +inline int strncasecmp(const char* s1, const char* s2, size_t len) +{ + return _strnicmp(s1, s2, len); +} + +inline int strcasecmp(const char* s1, const char* s2) +{ + return _stricmp(s1, s2); +} + +#endif + +#if OS(WINDOWS) || OS(LINUX) || OS(SOLARIS) +// FIXME: should check HAVE_STRNSTR + +inline char* strnstr(const char* buffer, const char* target, size_t bufferLength) +{ + size_t targetLength = strlen(target); + if (targetLength == 0) + return const_cast(buffer); + for (const char* start = buffer; *start && start + targetLength <= buffer + bufferLength; start++) { + if (*start == *target && strncmp(start + 1, target + 1, targetLength - 1) == 0) + return const_cast(start); + } + return 0; +} + +#endif + +#if COMPILER(RVCT) && __ARMCC_VERSION < 400000 + +int strcasecmp(const char* s1, const char* s2); +int strncasecmp(const char* s1, const char* s2, size_t len); #endif