/* * Copyright 2015 (c) Anna Schumaker. * * NOTE: All of these functions allocate and return a new string. It is the * caller's responsibility to free these strings by calling g_free(). */ #ifndef OCARINA_CORE_STRING_H #define OCARINA_CORE_STRING_H #include #include #include /* Convert number of seconds into a string with format mm:ss. */ gchar *string_sec2str(unsigned int); /* Convert number of seconds into a long-form time string. */ gchar *string_sec2str_long(unsigned int); /* Convert a struct tm to a locale-dependant date string. */ gchar *string_tm2str(struct tm *); /* * Compare two strings. * * if ret < 0: lhs < rhs, or rhs is empty. * if ret = 0: lhs == rhs. * if ret > 0: lhs > rhs, or lhs is empty. */ int string_compare_tokens(gchar **, gchar **); /* Returns True if the two strings match. */ static inline bool string_match(const gchar *a, const gchar *b) { return (a && b) ? g_utf8_collate(a, b) == 0 : false; } /* Returns True if one of the tokens begins with the specified prefix. */ bool string_match_token(const gchar *, gchar **); /* Returns True if string a is a subdirectory of string b. */ bool string_is_subdir(const gchar *, const gchar *); /* Return the length of the string, with NULL checks */ static inline int string_length(const gchar *str) { return str ? strlen(str) : 0; } #endif /* OCARINA_CORE_STRING_H */