Added strncmp(3).

This commit is contained in:
Jonas 'Sortie' Termansen 2011-11-20 17:07:01 +01:00
parent a6a2c400bf
commit 728bde3bee
2 changed files with 19 additions and 1 deletions

View File

@ -38,7 +38,7 @@ namespace Maxsi
char* Cat(char* Dest, const char* Src);
int Compare(const char* A, const char* B);
int CompareN(const char* A, const char* B, size_t MaxLength);
int StartsWith(const char* Haystack, const char* Needle);
bool StartsWith(const char* Haystack, const char* Needle);
int ToInt(const char* str);
int ConvertUInt8T(uint8_t num, char* dest);

View File

@ -85,6 +85,24 @@ namespace Maxsi
}
}
DUAL_FUNCTION(int, strncmp, CompareN, (const char* A, const char* B, size_t MaxLength))
{
while ( MaxLength-- )
{
if ( *A == '\0' && *B == '\0' ) { return 0; }
if ( *A < *B ) { return -1; }
if ( *A > *B ) { return 1; }
A++; B++;
}
return 0;
}
bool StartsWith(const char* haystack, const char* needle)
{
return CompareN(haystack, needle, Length(needle)) == 0;
}
char* Clone(const char* Input)
{
size_t InputSize = Length(Input);