Updated Spanish translation
[anjuta-git-plugin.git] / plugins / profiler / string-utils.c
blob7f35dc8636524f0710407f0a0e1fec5d8fe8f821
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 * string-utils.c
4 * Copyright (C) James Liggett 2006 <jrliggett@cox.net>
5 *
6 * string-utils.c is free software.
7 *
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.
24 #include <string.h>
25 #include <stdlib.h>
26 #include "string-utils.h"
28 #define NONE -1
30 gchar *read_to_whitespace(gchar *buffer, int *end_pos, int start_pos)
32 size_t buffer_length;
33 gint begin;
34 gint i;
35 gchar *string;
37 begin = NONE;
38 *end_pos = 0;
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 */
44 if (begin == NONE)
46 if (!g_ascii_isspace(buffer[i]))
47 begin = i;
49 else
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);
56 return string;
63 return NULL;
66 gchar *strip_whitespace(gchar* buffer)
68 size_t buffer_length;
69 gint i;
70 gchar *string;
72 buffer_length = strlen(buffer);
73 string = NULL;
75 for (i = 0; i < buffer_length; i++)
77 if (!g_ascii_isspace(buffer[i]))
78 break;
81 if (i < buffer_length)
82 string = g_strdup(&buffer[i]);
84 return string;
87 gchar *read_to_delimiter(gchar *buffer, gchar *delimiter)
89 gint i;
90 size_t buffer_length;
91 gchar *end; /* end of returned string */
92 gchar *string;
94 string = NULL;
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]))
102 break;
105 end = strstr(&buffer[i], delimiter);
107 if (end)
108 string = g_strndup(&buffer[i], (end - &buffer[i]));
110 return string;