1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 * Copyright (C) James Liggett 2006 <jrliggett@cox.net>
6 * string-utils.c is free software.
8 * You may redistribute it and/or modify it under the terms of the
9 * GNU General Public License, as published by the Free Software
10 * Foundation; either version 2, or (at your option) any later version.
12 * plugin.c is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 * See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with plugin.c. See the file "COPYING". If not,
19 * write to: The Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
26 #include "string-utils.h"
30 gchar
*read_to_whitespace(gchar
*buffer
, int *end_pos
, int start_pos
)
39 buffer_length
= strlen(buffer
);
41 for (i
= 0; i
< buffer_length
; i
++)
43 /* If we haven't found a string yet, ignore any leading whitespace */
46 if (!g_ascii_isspace(buffer
[i
]))
51 /* Found the end of the string or we're at the end of the buffer */
52 if (g_ascii_isspace(buffer
[i
]) || i
== (buffer_length
- 1))
54 *end_pos
= i
+ start_pos
;
55 string
= g_strndup(&buffer
[begin
], i
- begin
);
66 gchar
*strip_whitespace(gchar
* buffer
)
72 buffer_length
= strlen(buffer
);
75 for (i
= 0; i
< buffer_length
; i
++)
77 if (!g_ascii_isspace(buffer
[i
]))
81 if (i
< buffer_length
)
82 string
= g_strdup(&buffer
[i
]);
87 gchar
*read_to_delimiter(gchar
*buffer
, gchar
*delimiter
)
91 gchar
*end
; /* end of returned string */
96 /* Ignore any leading whitespace */
97 buffer_length
= strlen(buffer
);
99 for (i
= 0; i
< buffer_length
; i
++)
101 if (!g_ascii_isspace(buffer
[i
]))
105 end
= strstr(&buffer
[i
], delimiter
);
108 string
= g_strndup(&buffer
[i
], (end
- &buffer
[i
]));