You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

gregex.h 9.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /* GRegex -- regular expression API wrapper around PCRE.
  2. *
  3. * Copyright (C) 1999, 2000 Scott Wimer
  4. * Copyright (C) 2004, Matthias Clasen <mclasen@redhat.com>
  5. * Copyright (C) 2005 - 2007, Marco Barisione <marco@barisione.org>
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library 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. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #ifndef __G_REGEX_H__
  22. #define __G_REGEX_H__
  23. #include <glib.h>
  24. G_BEGIN_DECLS
  25. typedef enum
  26. {
  27. G_REGEX_ERROR_COMPILE,
  28. G_REGEX_ERROR_OPTIMIZE,
  29. G_REGEX_ERROR_REPLACE,
  30. G_REGEX_ERROR_MATCH,
  31. G_REGEX_ERROR_INTERNAL,
  32. /* These are the error codes from PCRE + 100 */
  33. G_REGEX_ERROR_STRAY_BACKSLASH = 101,
  34. G_REGEX_ERROR_MISSING_CONTROL_CHAR = 102,
  35. G_REGEX_ERROR_UNRECOGNIZED_ESCAPE = 103,
  36. G_REGEX_ERROR_QUANTIFIERS_OUT_OF_ORDER = 104,
  37. G_REGEX_ERROR_QUANTIFIER_TOO_BIG = 105,
  38. G_REGEX_ERROR_UNTERMINATED_CHARACTER_CLASS = 106,
  39. G_REGEX_ERROR_INVALID_ESCAPE_IN_CHARACTER_CLASS = 107,
  40. G_REGEX_ERROR_RANGE_OUT_OF_ORDER = 108,
  41. G_REGEX_ERROR_NOTHING_TO_REPEAT = 109,
  42. G_REGEX_ERROR_UNRECOGNIZED_CHARACTER = 112,
  43. G_REGEX_ERROR_POSIX_NAMED_CLASS_OUTSIDE_CLASS = 113,
  44. G_REGEX_ERROR_UNMATCHED_PARENTHESIS = 114,
  45. G_REGEX_ERROR_INEXISTENT_SUBPATTERN_REFERENCE = 115,
  46. G_REGEX_ERROR_UNTERMINATED_COMMENT = 118,
  47. G_REGEX_ERROR_EXPRESSION_TOO_LARGE = 120,
  48. G_REGEX_ERROR_MEMORY_ERROR = 121,
  49. G_REGEX_ERROR_VARIABLE_LENGTH_LOOKBEHIND = 125,
  50. G_REGEX_ERROR_MALFORMED_CONDITION = 126,
  51. G_REGEX_ERROR_TOO_MANY_CONDITIONAL_BRANCHES = 127,
  52. G_REGEX_ERROR_ASSERTION_EXPECTED = 128,
  53. G_REGEX_ERROR_UNKNOWN_POSIX_CLASS_NAME = 130,
  54. G_REGEX_ERROR_POSIX_COLLATING_ELEMENTS_NOT_SUPPORTED = 131,
  55. G_REGEX_ERROR_HEX_CODE_TOO_LARGE = 134,
  56. G_REGEX_ERROR_INVALID_CONDITION = 135,
  57. G_REGEX_ERROR_SINGLE_BYTE_MATCH_IN_LOOKBEHIND = 136,
  58. G_REGEX_ERROR_INFINITE_LOOP = 140,
  59. G_REGEX_ERROR_MISSING_SUBPATTERN_NAME_TERMINATOR = 142,
  60. G_REGEX_ERROR_DUPLICATE_SUBPATTERN_NAME = 143,
  61. G_REGEX_ERROR_MALFORMED_PROPERTY = 146,
  62. G_REGEX_ERROR_UNKNOWN_PROPERTY = 147,
  63. G_REGEX_ERROR_SUBPATTERN_NAME_TOO_LONG = 148,
  64. G_REGEX_ERROR_TOO_MANY_SUBPATTERNS = 149,
  65. G_REGEX_ERROR_INVALID_OCTAL_VALUE = 151,
  66. G_REGEX_ERROR_TOO_MANY_BRANCHES_IN_DEFINE = 154,
  67. G_REGEX_ERROR_DEFINE_REPETION = 155,
  68. G_REGEX_ERROR_INCONSISTENT_NEWLINE_OPTIONS = 156,
  69. G_REGEX_ERROR_MISSING_BACK_REFERENCE = 157
  70. } GRegexError;
  71. #define G_REGEX_ERROR g_regex_error_quark ()
  72. GQuark g_regex_error_quark (void);
  73. /* Remember to update G_REGEX_COMPILE_MASK in gregex.c after
  74. * adding a new flag. */
  75. typedef enum
  76. {
  77. G_REGEX_CASELESS = 1 << 0,
  78. G_REGEX_MULTILINE = 1 << 1,
  79. G_REGEX_DOTALL = 1 << 2,
  80. G_REGEX_EXTENDED = 1 << 3,
  81. G_REGEX_ANCHORED = 1 << 4,
  82. G_REGEX_DOLLAR_ENDONLY = 1 << 5,
  83. G_REGEX_UNGREEDY = 1 << 9,
  84. G_REGEX_RAW = 1 << 11,
  85. G_REGEX_NO_AUTO_CAPTURE = 1 << 12,
  86. G_REGEX_OPTIMIZE = 1 << 13,
  87. G_REGEX_DUPNAMES = 1 << 19,
  88. G_REGEX_NEWLINE_CR = 1 << 20,
  89. G_REGEX_NEWLINE_LF = 1 << 21,
  90. G_REGEX_NEWLINE_CRLF = G_REGEX_NEWLINE_CR | G_REGEX_NEWLINE_LF
  91. } GRegexCompileFlags;
  92. /* Remember to update G_REGEX_MATCH_MASK in gregex.c after
  93. * adding a new flag. */
  94. typedef enum
  95. {
  96. G_REGEX_MATCH_ANCHORED = 1 << 4,
  97. G_REGEX_MATCH_NOTBOL = 1 << 7,
  98. G_REGEX_MATCH_NOTEOL = 1 << 8,
  99. G_REGEX_MATCH_NOTEMPTY = 1 << 10,
  100. G_REGEX_MATCH_PARTIAL = 1 << 15,
  101. G_REGEX_MATCH_NEWLINE_CR = 1 << 20,
  102. G_REGEX_MATCH_NEWLINE_LF = 1 << 21,
  103. G_REGEX_MATCH_NEWLINE_CRLF = G_REGEX_MATCH_NEWLINE_CR | G_REGEX_MATCH_NEWLINE_LF,
  104. G_REGEX_MATCH_NEWLINE_ANY = 1 << 22
  105. } GRegexMatchFlags;
  106. typedef struct _GRegex GRegex;
  107. typedef struct _GMatchInfo GMatchInfo;
  108. typedef gboolean (*GRegexEvalCallback) (const GMatchInfo *match_info,
  109. GString *result,
  110. gpointer user_data);
  111. GRegex *g_regex_new (const gchar *pattern,
  112. GRegexCompileFlags compile_options,
  113. GRegexMatchFlags match_options,
  114. GError **error);
  115. GRegex *g_regex_ref (GRegex *regex);
  116. void g_regex_unref (GRegex *regex);
  117. const gchar *g_regex_get_pattern (const GRegex *regex);
  118. gint g_regex_get_max_backref (const GRegex *regex);
  119. gint g_regex_get_capture_count (const GRegex *regex);
  120. gint g_regex_get_string_number (const GRegex *regex,
  121. const gchar *name);
  122. gchar *g_regex_escape_string (const gchar *string,
  123. gint length);
  124. /* Matching. */
  125. gboolean g_regex_match_simple (const gchar *pattern,
  126. const gchar *string,
  127. GRegexCompileFlags compile_options,
  128. GRegexMatchFlags match_options);
  129. gboolean g_regex_match (const GRegex *regex,
  130. const gchar *string,
  131. GRegexMatchFlags match_options,
  132. GMatchInfo **match_info);
  133. gboolean g_regex_match_full (const GRegex *regex,
  134. const gchar *string,
  135. gssize string_len,
  136. gint start_position,
  137. GRegexMatchFlags match_options,
  138. GMatchInfo **match_info,
  139. GError **error);
  140. gboolean g_regex_match_all (const GRegex *regex,
  141. const gchar *string,
  142. GRegexMatchFlags match_options,
  143. GMatchInfo **match_info);
  144. gboolean g_regex_match_all_full (const GRegex *regex,
  145. const gchar *string,
  146. gssize string_len,
  147. gint start_position,
  148. GRegexMatchFlags match_options,
  149. GMatchInfo **match_info,
  150. GError **error);
  151. /* String splitting. */
  152. gchar **g_regex_split_simple (const gchar *pattern,
  153. const gchar *string,
  154. GRegexCompileFlags compile_options,
  155. GRegexMatchFlags match_options);
  156. gchar **g_regex_split (const GRegex *regex,
  157. const gchar *string,
  158. GRegexMatchFlags match_options);
  159. gchar **g_regex_split_full (const GRegex *regex,
  160. const gchar *string,
  161. gssize string_len,
  162. gint start_position,
  163. GRegexMatchFlags match_options,
  164. gint max_tokens,
  165. GError **error);
  166. /* String replacement. */
  167. gchar *g_regex_replace (const GRegex *regex,
  168. const gchar *string,
  169. gssize string_len,
  170. gint start_position,
  171. const gchar *replacement,
  172. GRegexMatchFlags match_options,
  173. GError **error);
  174. gchar *g_regex_replace_literal (const GRegex *regex,
  175. const gchar *string,
  176. gssize string_len,
  177. gint start_position,
  178. const gchar *replacement,
  179. GRegexMatchFlags match_options,
  180. GError **error);
  181. gchar *g_regex_replace_eval (const GRegex *regex,
  182. const gchar *string,
  183. gssize string_len,
  184. gint start_position,
  185. GRegexMatchFlags match_options,
  186. GRegexEvalCallback eval,
  187. gpointer user_data,
  188. GError **error);
  189. gboolean g_regex_check_replacement (const gchar *replacement,
  190. gboolean *has_references,
  191. GError **error);
  192. /* Match info */
  193. GRegex *g_match_info_get_regex (const GMatchInfo *match_info);
  194. const gchar *g_match_info_get_string (const GMatchInfo *match_info);
  195. void g_match_info_free (GMatchInfo *match_info);
  196. gboolean g_match_info_next (GMatchInfo *match_info,
  197. GError **error);
  198. gboolean g_match_info_matches (const GMatchInfo *match_info);
  199. gint g_match_info_get_match_count (const GMatchInfo *match_info);
  200. gboolean g_match_info_is_partial_match (const GMatchInfo *match_info);
  201. gchar *g_match_info_expand_references(const GMatchInfo *match_info,
  202. const gchar *string_to_expand,
  203. GError **error);
  204. gchar *g_match_info_fetch (const GMatchInfo *match_info,
  205. gint match_num);
  206. gboolean g_match_info_fetch_pos (const GMatchInfo *match_info,
  207. gint match_num,
  208. gint *start_pos,
  209. gint *end_pos);
  210. gchar *g_match_info_fetch_named (const GMatchInfo *match_info,
  211. const gchar *name);
  212. gboolean g_match_info_fetch_named_pos (const GMatchInfo *match_info,
  213. const gchar *name,
  214. gint *start_pos,
  215. gint *end_pos);
  216. gchar **g_match_info_fetch_all (const GMatchInfo *match_info);
  217. G_END_DECLS
  218. #endif /* __G_REGEX_H__ */