blob: a8fb48f19224bae38d3e0aadaf122b3bddd1b080 [file] [log] [blame]
Steven Rostedtf7d82352012-04-06 00:47:53 +02001/*
2 * Copyright (C) 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
3 *
4 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation;
8 * version 2.1 of the License (not later!)
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 */
21#ifndef __UTIL_H
22#define __UTIL_H
23
24#include <ctype.h>
25
26static inline char *strim(char *string)
27{
28 char *ret;
29
30 if (!string)
31 return NULL;
32 while (*string) {
33 if (!isspace(*string))
34 break;
35 string++;
36 }
37 ret = string;
38
39 string = ret + strlen(ret) - 1;
40 while (string > ret) {
41 if (!isspace(*string))
42 break;
43 string--;
44 }
45 string[1] = 0;
46
47 return ret;
48}
49
50static inline int has_text(const char *text)
51{
52 if (!text)
53 return 0;
54
55 while (*text) {
56 if (!isspace(*text))
57 return 1;
58 text++;
59 }
60
61 return 0;
62}
63
64#endif