X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Futil.h;h=63f4e3dff2730db346979442061c4e9f48a299b5;hb=442e00839e4fc3c11506f5c8a9477b465865aecc;hp=fac08ca43c1b4e96ddf5db4be5da340f05cc657d;hpb=3a83211689bdf4ab617a4fb79e11980c50918123;p=elogind.git diff --git a/src/shared/util.h b/src/shared/util.h index fac08ca43..63f4e3dff 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -106,9 +106,19 @@ static inline bool isempty(const char *p) { return !p || !p[0]; } +static inline const char *startswith(const char *s, const char *prefix) { + if (strncmp(s, prefix, strlen(prefix)) == 0) + return s + strlen(prefix); + return NULL; +} + +static inline const char *startswith_no_case(const char *s, const char *prefix) { + if (strncasecmp(s, prefix, strlen(prefix)) == 0) + return s + strlen(prefix); + return NULL; +} + char *endswith(const char *s, const char *postfix) _pure_; -char *startswith(const char *s, const char *prefix) _pure_; -char *startswith_no_case(const char *s, const char *prefix) _pure_; bool first_word(const char *s, const char *word) _pure_; @@ -374,6 +384,22 @@ void columns_lines_cache_reset(int _unused_ signum); bool on_tty(void); +static inline const char *ansi_highlight(void) { + return on_tty() ? ANSI_HIGHLIGHT_ON : ""; +} + +static inline const char *ansi_highlight_red(void) { + return on_tty() ? ANSI_HIGHLIGHT_RED_ON : ""; +} + +static inline const char *ansi_highlight_green(void) { + return on_tty() ? ANSI_HIGHLIGHT_GREEN_ON : ""; +} + +static inline const char *ansi_highlight_off(void) { + return on_tty() ? ANSI_HIGHLIGHT_OFF : ""; +} + int running_in_chroot(void); char *ellipsize(const char *s, size_t length, unsigned percent); @@ -735,3 +761,5 @@ static inline void _reset_locale_(struct _locale_struct_ *s) { bool id128_is_valid(const char *s) _pure_; void parse_user_at_host(char *arg, char **user, char **host); + +int split_pair(const char *s, const char *sep, char **l, char **r);