2 * Copyright (C) 2012,2013 Toni Gundogdu <legatvs@gmail.com>
4 * This file is part of libquvi-scripts <http://quvi.sourceforge.net>.
6 * This program is free software: you can redistribute it and/or
7 * modify it under the terms of the GNU Affero General Public
8 * License as published by the Free Software Foundation, either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General
17 * Public License along with this program. If not, see
18 * <http://www.gnu.org/licenses/>.
28 gboolean
match(const gchar
*s
, const gchar
*p
)
36 re
= g_regex_new(p
, G_REGEX_MULTILINE
, 0, &err
);
40 g_warning(_W
, __func__
, err
->message
);
46 r
= g_regex_match(re
, s
, 0, &m
);
57 capture_t
capture_new(const gchar
*str
, const gchar
*patt
,
58 const GRegexCompileFlags flags
)
60 capture_t p
= g_new0(struct capture_s
, 1);
62 p
->re
= g_regex_new(patt
, flags
, 0, &p
->e
);
65 g_warning(_W
, __func__
, p
->e
->message
);
70 g_regex_match_full(p
->re
, str
, -1, 0, 0, &p
->m
, &p
->e
);
73 g_warning(_W
, __func__
, p
->e
->message
);
80 gboolean
capture_matches(capture_t p
)
83 g_assert(p
->m
!= NULL
);
84 return (g_match_info_matches(p
->m
));
87 gchar
*capture_fetch(capture_t p
, const gint i
)
90 g_assert(p
->m
!= NULL
);
91 return (g_match_info_fetch(p
->m
, i
));
94 gboolean
capture_next(capture_t p
)
97 g_assert(p
->m
!= NULL
);
99 g_match_info_next(p
->m
, &p
->e
);
102 g_warning(_W
, __func__
, p
->e
->message
);
108 void capture_free(capture_t p
)
113 g_match_info_free(p
->m
);
114 g_regex_unref(p
->re
);
122 /* vim: set ts=2 sw=2 tw=72 expandtab: */