Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Core/GameEngine/Include/Common/UnicodeString.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,30 @@ class UnicodeString
*/
int compareNoCase(const WideChar* s) const;

/**
return true iff self starts with the given string.
*/
Bool startsWith(const WideChar* p) const;
inline Bool startsWith(const UnicodeString& stringSrc) const { return startsWith(stringSrc.str()); }

/**
return true iff self starts with the given string. (case insensitive)
*/
Bool startsWithNoCase(const WideChar* p) const;
inline Bool startsWithNoCase(const UnicodeString& stringSrc) const { return startsWithNoCase(stringSrc.str()); }

/**
return true iff self ends with the given string.
*/
Bool endsWith(const WideChar* p) const;
Bool endsWith(const UnicodeString& stringSrc) const { return endsWith(stringSrc.str()); }

/**
return true iff self ends with the given string. (case insensitive)
*/
Bool endsWithNoCase(const WideChar* p) const;
Bool endsWithNoCase(const UnicodeString& stringSrc) const { return endsWithNoCase(stringSrc.str()); }

/**
conceptually similar to strtok():
Expand Down
40 changes: 4 additions & 36 deletions Core/GameEngine/Source/Common/System/AsciiString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,57 +477,25 @@ void AsciiString::format_va(const char* format, va_list args)
// -----------------------------------------------------
Bool AsciiString::startsWith(const char* p) const
{
if (*p == 0)
return true; // everything starts with the empty string

int lenThis = getLength();
int lenThat = strlen(p);
if (lenThis < lenThat)
return false; // that must be smaller than this

return strncmp(peek(), p, lenThat) == 0;
return ::startsWith(peek(), p);
}

// -----------------------------------------------------
Bool AsciiString::startsWithNoCase(const char* p) const
{
if (*p == 0)
return true; // everything starts with the empty string

int lenThis = getLength();
int lenThat = strlen(p);
if (lenThis < lenThat)
return false; // that must be smaller than this

return strnicmp(peek(), p, lenThat) == 0;
return ::startsWithNoCase(peek(), p);
}

// -----------------------------------------------------
Bool AsciiString::endsWith(const char* p) const
{
if (*p == 0)
return true; // everything ends with the empty string

int lenThis = getLength();
int lenThat = strlen(p);
if (lenThis < lenThat)
return false; // that must be smaller than this

return strncmp(peek() + lenThis - lenThat, p, lenThat) == 0;
return ::endsWith(peek(), p);
}

// -----------------------------------------------------
Bool AsciiString::endsWithNoCase(const char* p) const
{
if (*p == 0)
return true; // everything ends with the empty string

int lenThis = getLength();
int lenThat = strlen(p);
if (lenThis < lenThat)
return false; // that must be smaller than this

return strnicmp(peek() + lenThis - lenThat, p, lenThat) == 0;
return ::endsWithNoCase(peek(), p);
}

//-----------------------------------------------------------------------------
Expand Down
24 changes: 24 additions & 0 deletions Core/GameEngine/Source/Common/System/UnicodeString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,30 @@ void UnicodeString::format_va(const WideChar* format, va_list args)
}
}

// -----------------------------------------------------
Bool UnicodeString::startsWith(const WideChar* p) const
{
return ::startsWith(peek(), p);
}

// -----------------------------------------------------
Bool UnicodeString::startsWithNoCase(const WideChar* p) const
{
return ::startsWithNoCase(peek(), p);
}

// -----------------------------------------------------
Bool UnicodeString::endsWith(const WideChar* p) const
{
return ::endsWith(peek(), p);
}

// -----------------------------------------------------
Bool UnicodeString::endsWithNoCase(const WideChar* p) const
{
return ::endsWithNoCase(peek(), p);
}

//-----------------------------------------------------------------------------
Bool UnicodeString::nextToken(UnicodeString* tok, UnicodeString delimiters)
{
Expand Down
104 changes: 104 additions & 0 deletions Core/Libraries/Source/WWVegas/WWLib/stringex.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,107 @@ template<size_t Size> size_t strlcat_t(char (&dst)[Size], const char *src) { ret
template<size_t Size> size_t strlmove_t(char (&dst)[Size], const char *src) { return strlmove_t(dst, src, Size); }
template<size_t Size> size_t strlmcat_t(char (&dst)[Size], const char *src) { return strlmcat_t(dst, src, Size); }
#endif

inline bool startsWith(const char *str, const char *prefix)
{
if (*prefix == char(0))
return true; // everything starts with the empty string

const size_t strlen = ::strlen(str);
const size_t prefixlen = ::strlen(prefix);
if (strlen < prefixlen)
return false; // prefix must be as long or shorter than str

return ::strncmp(str, prefix, prefixlen) == 0;
}

inline bool startsWith(const wchar_t *str, const wchar_t *prefix)
{
if (*prefix == wchar_t(0))
return true; // everything starts with the empty string

const size_t strlen = ::wcslen(str);
const size_t prefixlen = ::wcslen(prefix);
if (strlen < prefixlen)
return false; // prefix must be as long or shorter than str

return ::wcsncmp(str, prefix, prefixlen) == 0;
}

inline bool startsWithNoCase(const char *str, const char *prefix)
{
if (*prefix == char(0))
return true; // everything starts with the empty string

const size_t strlen = ::strlen(str);
const size_t prefixlen = ::strlen(prefix);
if (strlen < prefixlen)
return false; // prefix must be as long or shorter than str

return ::strnicmp(str, prefix, prefixlen) == 0;
}

inline bool startsWithNoCase(const wchar_t *str, const wchar_t *prefix)
{
if (*prefix == wchar_t(0))
return true; // everything starts with the empty string

const size_t strlen = ::wcslen(str);
const size_t prefixlen = ::wcslen(prefix);
if (strlen < prefixlen)
return false; // prefix must be as long or shorter than str

return ::wcsnicmp(str, prefix, prefixlen) == 0;
}

inline bool endsWith(const char *str, const char *suffix)
{
if (*suffix == char(0))
return true; // everything ends with the empty string

const size_t strlen = ::strlen(str);
const size_t suffixlen = ::strlen(suffix);
if (strlen < suffixlen)
return false; // suffix must be as long or shorter than str

return ::strncmp(str + strlen - suffixlen, suffix, suffixlen) == 0;
}

inline bool endsWith(const wchar_t *str, const wchar_t *suffix)
{
if (*suffix == wchar_t(0))
return true; // everything ends with the empty string

const size_t strlen = ::wcslen(str);
const size_t suffixlen = ::wcslen(suffix);
if (strlen < suffixlen)
return false; // suffix must be as long or shorter than str

return ::wcsncmp(str + strlen - suffixlen, suffix, suffixlen) == 0;
}

inline bool endsWithNoCase(const char *str, const char *suffix)
{
if (*suffix == char(0))
return true; // everything ends with the empty string

const size_t strlen = ::strlen(str);
const size_t suffixlen = ::strlen(suffix);
if (strlen < suffixlen)
return false; // suffix must be as long or shorter than str

return ::strnicmp(str + strlen - suffixlen, suffix, suffixlen) == 0;
}

inline bool endsWithNoCase(const wchar_t *str, const wchar_t *suffix)
{
if (*suffix == wchar_t(0))
return true; // everything ends with the empty string

const size_t strlen = ::wcslen(str);
const size_t suffixlen = ::wcslen(suffix);
if (strlen < suffixlen)
return false; // suffix must be as long or shorter than str

return ::wcsnicmp(str + strlen - suffixlen, suffix, suffixlen) == 0;
}
Loading