X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fnetradiant.git;a=blobdiff_plain;f=libs%2Fstring%2Fstring.h;h=ff7dc4536c9245ce116e612534f0d1ff826a49a6;hp=a6de0673913009b899cead876a192372223128b6;hb=0f2e4b773715b05595f1c149d99fcc4795e01948;hpb=e4287c28bb2dafedc81c66e63951d947cfbeb225 diff --git a/libs/string/string.h b/libs/string/string.h index a6de0673..ff7dc453 100644 --- a/libs/string/string.h +++ b/libs/string/string.h @@ -22,6 +22,8 @@ #if !defined( INCLUDED_STRING_STRING_H ) #define INCLUDED_STRING_STRING_H +#include "globaldefs.h" + /// \file /// C-style null-terminated-character-array string library. @@ -81,7 +83,7 @@ inline bool string_greater( const char* string, const char* other ){ /// Returns 0 if \p string is lexicographically equal to \p other after converting both to lower-case. /// O(n) inline int string_compare_nocase( const char* string, const char* other ){ -#ifdef WIN32 +#if GDEF_OS_WINDOWS return _stricmp( string, other ); #else return strcasecmp( string, other ); @@ -94,7 +96,7 @@ inline int string_compare_nocase( const char* string, const char* other ){ /// Treats all ascii characters as lower-case during comparisons. /// O(n) inline int string_compare_nocase_n( const char* string, const char* other, std::size_t n ){ -#ifdef WIN32 +#if GDEF_OS_WINDOWS return _strnicmp( string, other, n ); #else return strncasecmp( string, other, n ); @@ -141,6 +143,13 @@ inline bool string_equal_prefix( const char* string, const char* prefix ){ return string_equal_n( string, prefix, string_length( prefix ) ); } +/// \brief Returns true if the ending of \p string is equal to \p suffix. +/// O(n) +inline bool string_equal_suffix( const char* string, const char* suffix){ + const char *s = string + string_length( string ) - string_length( suffix ); + return string_equal_n( s , suffix, string_length( suffix ) ); +} + /// \brief Copies \p other into \p string and returns \p string. /// Assumes that the space allocated for \p string is at least string_length(other) + 1. /// O(n) @@ -187,6 +196,14 @@ inline char* string_new( std::size_t length ){ return string_new( length, allocator ); } +/// \brief Allocates a new buffer large enough to hold two concatenated strings and fills it with strings. +inline char* string_new_concat( const char* a, const char* b ){ + char* str = string_new( string_length( a ) + string_length( b ) ); + strcpy( str, a ); + strcat( str, b ); + return str; +} + /// \brief Deallocates the \p buffer large enough to hold \p length characters. inline void string_release( char* string, std::size_t length ){ DefaultAllocator allocator;