2015-09-08 09:14:39 -04:00
|
|
|
/*
|
2015-01-26 09:40:48 -05:00
|
|
|
* Copyright 2015 (c) Anna Schumaker.
|
2015-09-08 09:14:39 -04:00
|
|
|
*
|
|
|
|
* 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().
|
2015-01-26 09:40:48 -05:00
|
|
|
*/
|
|
|
|
#ifndef OCARINA_CORE_STRING_H
|
|
|
|
#define OCARINA_CORE_STRING_H
|
|
|
|
|
2015-09-02 08:02:41 -04:00
|
|
|
#include <glib.h>
|
2015-09-08 09:39:35 -04:00
|
|
|
#include <string.h>
|
2016-04-26 07:37:58 -04:00
|
|
|
#include <stdbool.h>
|
2015-01-26 09:40:48 -05:00
|
|
|
|
|
|
|
|
2015-09-08 09:14:39 -04:00
|
|
|
/* Convert number of seconds into a string with format mm:ss. */
|
2015-09-02 08:02:41 -04:00
|
|
|
gchar *string_sec2str(unsigned int);
|
|
|
|
|
2015-09-08 09:14:39 -04:00
|
|
|
/* Convert number of seconds into a long-form time string. */
|
2015-09-03 09:31:48 -04:00
|
|
|
gchar *string_sec2str_long(unsigned int);
|
|
|
|
|
2015-10-28 03:55:40 -04:00
|
|
|
/* Convert a struct tm to a locale-dependant date string. */
|
|
|
|
gchar *string_tm2str(struct tm *);
|
|
|
|
|
2015-09-24 13:57:42 -04:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2016-05-19 11:00:40 -04:00
|
|
|
int string_compare_tokens(gchar **, gchar **);
|
2015-09-24 13:57:42 -04:00
|
|
|
|
2016-04-26 07:37:58 -04:00
|
|
|
/* Returns True if the two strings match. */
|
|
|
|
static inline bool string_match(const gchar *a, const gchar *b)
|
|
|
|
{
|
2016-05-19 12:52:21 -04:00
|
|
|
return (a && b) ? g_utf8_collate(a, b) == 0 : false;
|
2016-04-26 07:37:58 -04:00
|
|
|
}
|
|
|
|
|
2016-05-19 12:02:56 -04:00
|
|
|
/* Returns True if one of the tokens begins with the specified prefix. */
|
|
|
|
bool string_match_token(const gchar *, gchar **);
|
|
|
|
|
2017-04-11 09:12:17 -04:00
|
|
|
/* Returns True if string a is a subdirectory of string b. */
|
|
|
|
bool string_is_subdir(const gchar *, const gchar *);
|
|
|
|
|
2016-03-29 08:11:49 -04:00
|
|
|
/* Return the length of the string, with NULL checks */
|
|
|
|
static inline int string_length(const gchar *str)
|
|
|
|
{
|
|
|
|
return str ? strlen(str) : 0;
|
|
|
|
}
|
|
|
|
|
2015-01-26 09:40:48 -05:00
|
|
|
#endif /* OCARINA_CORE_STRING_H */
|