1 #ifndef GO_REGUTF8_H
2 #define GO_REGUTF8_H
3 
4 #include <glib.h>
5 #include <glib-object.h>
6 
7 /* -------------------------------------------------------------------------- */
8 
9 G_BEGIN_DECLS
10 
11 /*
12  * This enum snarfed from glibc.  Insofar it is copyrightable, it is
13  * Copyright (C) 1985,1989-93,1995-98,2000,2001,2002,2003
14  * Free Software Foundation, Inc.
15  */
16 enum {
17 	GO_REG_NOERROR = 0,	/* Success.  */
18 	GO_REG_NOMATCH,		/* Didn't find a match (for regexec).  */
19 
20 	/* POSIX regcomp return error codes.  (In the order listed in the
21 	   standard.)  */
22 	GO_REG_BADPAT,		/* Invalid pattern.  */
23 	GO_REG_ECOLLATE,		/* Inalid collating element.  */
24 	GO_REG_ECTYPE,		/* Invalid character class name.  */
25 	GO_REG_EESCAPE,		/* Trailing backslash.  */
26 	GO_REG_ESUBREG,		/* Invalid back reference.  */
27 	GO_REG_EBRACK,		/* Unmatched left bracket.  */
28 	GO_REG_EPAREN,		/* Parenthesis imbalance.  */
29 	GO_REG_EBRACE,		/* Unmatched \{.  */
30 	GO_REG_BADBR,		/* Invalid contents of \{\}.  */
31 	GO_REG_ERANGE,		/* Invalid range end.  */
32 	GO_REG_ESPACE,		/* Ran out of memory.  */
33 	GO_REG_BADRPT,		/* No preceding re for repetition op.  */
34 
35 	/* Error codes we've added.  */
36 	GO_REG_EEND,		/* Premature end.  */
37 	GO_REG_ESIZE,		/* Compiled pattern bigger than 2^16 bytes.  */
38 	GO_REG_ERPAREN		/* Unmatched ) or \); not returned from regcomp.  */
39 };
40 #define GO_REG_OK GO_REG_NOERROR
41 
42 /* eflags bits.  */
43 enum {
44 	GO_REG_NOTBOL = 1,
45 	GO_REG_NOTEOL = 2
46 };
47 
48 /* cflags bits.  */
49 enum {
50 	GO_REG_EXTENDED = 1,
51 	GO_REG_ICASE = 2,
52 	GO_REG_NEWLINE = 4,
53 	GO_REG_NOSUB = 8
54 };
55 
56 /* Like POSIX' regex_t.  */
57 typedef struct {
58 	size_t re_nsub;
59 	/*< private >*/
60 	gboolean nosub;
61 	void *ppcre;
62 } GORegexp;
63 
64 /* Like POSIX' regoff_t.  */
65 typedef int GORegoff;
66 
67 /* Like POSIX' regmatch_t.  */
68 typedef struct {
69 	GORegoff rm_so, rm_eo;
70 } GORegmatch;
71 
72 int go_regcomp (GORegexp * preg, const char *pattern, int cflags);
73 int go_regexec (const GORegexp * preg, const char *string, size_t nmatch,
74 		GORegmatch pmatch[], int eflags);
75 size_t go_regerror (int errcode, const GORegexp * preg, char *errbuf,
76 		    size_t errbuf_size);
77 void go_regfree (GORegexp * preg);
78 
79 /* -------------------------------------------------------------------------- */
80 
81 #define GO_TYPE_SEARCH_REPLACE        (go_search_replace_get_type ())
82 #define GO_SEARCH_REPLACE(o)          (G_TYPE_CHECK_INSTANCE_CAST ((o), GO_TYPE_SEARCH_REPLACE, GOSearchReplace))
83 #define GO_IS_SEARCH_REPLACE(o)       (G_TYPE_CHECK_INSTANCE_TYPE ((o), GO_TYPE_SEARCH_REPLACE))
84 
85 typedef struct _GoSearchReplace {
86 	GObject base;
87 
88 	/*< public >*/
89 	char *search_text;
90 	char *replace_text;
91 
92 	GORegexp *comp_search;
93 	gboolean is_regexp;	/* Search text is a regular expression.  */
94 	gboolean ignore_case;	/* Consider "a" and "A" the same.  */
95 	gboolean preserve_case;	/* Like Emacs' case-replace.  */
96 	gboolean match_words;	/* Like grep -w.  */
97 
98 	/*< private >*/
99 	gboolean plain_replace;
100 } GOSearchReplace;
101 
102 typedef struct {
103 	GObjectClass g_object_class;
104 } GOSearchReplaceClass;
105 
106 
107 GQuark           go_search_replace_error_quark (void);
108 GType            go_search_replace_get_type (void);
109 
110 gboolean         go_search_replace_verify (GOSearchReplace *sr, gboolean repl, GError **err);
111 
112 gboolean         go_search_match_string (GOSearchReplace *sr, const char *src);
113 char *           go_search_replace_string (GOSearchReplace *sr, const char *src);
114 
115 const char *go_regexp_quote1 (GString *target, const char *s);
116 void go_regexp_quote (GString *target, const char *s);
117 
118 G_END_DECLS
119 
120 #endif /* GO_REGUTF8_H */
121