1 //
2 // HtRegexReplace.h
3 //
4 // HtRegexReplace: A subclass of HtRegex that can perform replacements
5 //
6 // Part of the ht://Dig package   <http://www.htdig.org/>
7 // Copyright (c) 2000-2004 The ht://Dig Group
8 // For copyright details, see the file COPYING in your distribution
9 // or the GNU Library General Public License (LGPL) version 2 or later
10 // <http://www.gnu.org/copyleft/lgpl.html>
11 //
12 // $Id: HtRegexReplace.h,v 1.4 2004/05/28 13:15:21 lha Exp $
13 //
14 
15 #ifndef	_HtRegexReplace_h_
16 #define	_HtRegexReplace_h_
17 
18 #ifdef HAVE_CONFIG_H
19 #include "htconfig.h"
20 #endif /* HAVE_CONFIG_H */
21 
22 #include "HtRegex.h"
23 
24 class HtRegexReplace : public HtRegex
25 {
26 public:
27     //
28     // Construction/Destruction
29     //
30     HtRegexReplace();
31     HtRegexReplace(const char *from, const char *to, int case_sensitive = 0);
32     virtual ~HtRegexReplace();
33 
34     //
35     // Methods for setting the replacement pattern
36     //
setReplace(const String & str)37 	void	setReplace(const String& str) { setReplace(str.get()); }
38 	void	setReplace(const char *str);
39 
40     //
41     // Methods for replacing
42     //
43     int		replace(String &str, int nullpattern = 0, int nullstr = 0);
44 
45 protected:
46 	char	*repBuf;      // Replace text.
47 	size_t	segSize, segUsed;
48 	int		*segMark;
49 	size_t	repLen;
50 
51     regmatch_t		regs[10];
52 
53 	// Various private methods
54 	void putMark(int n);
55 	void empty();
56 };
57 
58 #endif
59