axl_strchr
This commit is contained in:
parent
f98d39b977
commit
8016f64db4
3 changed files with 33 additions and 0 deletions
16
axl_string.c
16
axl_string.c
|
|
@ -121,3 +121,19 @@ i32 axl_strncmp(const i8* s1, const i8* s2, u32 n)
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const i8* axl_strchr(const i8* str, i8 c)
|
||||
{
|
||||
u32 i = 0;
|
||||
|
||||
while(str[i] != '\0')
|
||||
{
|
||||
if(str[i] == c)
|
||||
{
|
||||
return str + i;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,5 +9,6 @@ i8* axl_strncpy(i8* dst, const i8* src, u32 n);
|
|||
i8* axl_strcat(i8* dst, const i8* src);
|
||||
i8* axl_strncat(i8* dst, const i8* src, u32 n);
|
||||
i32 axl_strcmp(const i8* s1, const i8* s2);
|
||||
const i8* axl_strchr(const i8* str, i8 c);
|
||||
|
||||
#endif // AXL_STRING
|
||||
|
|
|
|||
|
|
@ -229,6 +229,22 @@ KOAN(strncat_zero_n)
|
|||
ASSERT_STR_EQ("hi", (char*)dst);
|
||||
}
|
||||
|
||||
KOAN(strchr_returns_proper_ptr)
|
||||
{
|
||||
i8 str[] = "hi Mark";
|
||||
|
||||
ASSERT_PTR_EQ(str + 0, axl_strchr(str, 'h'));
|
||||
ASSERT_PTR_EQ(str + 1, axl_strchr(str, 'i'));
|
||||
ASSERT_PTR_EQ(str + 2, axl_strchr(str, ' '));
|
||||
ASSERT_PTR_EQ(str + 3, axl_strchr(str, 'M'));
|
||||
ASSERT_PTR_EQ(str + 4, axl_strchr(str, 'a'));
|
||||
ASSERT_PTR_EQ(str + 5, axl_strchr(str, 'r'));
|
||||
ASSERT_PTR_EQ(str + 6, axl_strchr(str, 'k'));
|
||||
|
||||
ASSERT_NULL(axl_strchr(str, '\0'));
|
||||
ASSERT_NULL(axl_strchr(str, 'm'));
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
axl_init();
|
||||
|
|
|
|||
Loading…
Reference in a new issue