Skip to content

Commit

Permalink
libdeng1|API: Added Str_StartsWith()
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Jan 23, 2014
1 parent 3d6eca1 commit e1efab8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
13 changes: 12 additions & 1 deletion doomsday/libdeng1/include/de/str.h
Expand Up @@ -299,6 +299,17 @@ DENG_PUBLIC Str *Str_Strip(Str *ds);
*/
DENG_PUBLIC Str *Str_ReplaceAll(Str *ds, char from, char to);

/**
* Determines if the string starts starts with the given substring. The comparison
* is done case sensitively.
*
* @param ds String instance.
* @param text Text to look for at the start of @a ds.
*
* @return @c true, if the string is found.
*/
DENG_PUBLIC dd_bool Str_StartsWith(Str const *ds, char const *text);

/**
* Determines if the string ends with a specific suffic. The comparison is done
* case sensitively.
Expand All @@ -308,7 +319,7 @@ DENG_PUBLIC Str *Str_ReplaceAll(Str *ds, char from, char to);
*
* @return @c true, if the string is found.
*/
DENG_PUBLIC dd_bool Str_EndsWith(Str *ds, char const *text);
DENG_PUBLIC dd_bool Str_EndsWith(Str const *ds, char const *text);

/**
* Extract a line of text from the source.
Expand Down
9 changes: 8 additions & 1 deletion doomsday/libdeng1/src/str.c
Expand Up @@ -557,7 +557,14 @@ ddstring_t *Str_Strip(ddstring_t *str)
return Str_Strip2(str, NULL/*not interested in the stripped character count*/);
}

dd_bool Str_EndsWith(Str *ds, char const *text)
dd_bool Str_StartsWith(Str const *ds, char const *text)
{
size_t len = strlen(text);
if(Str_Size(ds) < len) return false;
return !strncmp(ds->str, text, len);
}

dd_bool Str_EndsWith(Str const *ds, char const *text)
{
size_t len = strlen(text);
if(Str_Size(ds) < len) return false;
Expand Down

0 comments on commit e1efab8

Please sign in to comment.