comparison liboctave/regex-match.cc @ 11586:12df7854fa7c

strip trailing whitespace from source files
author John W. Eaton <jwe@octave.org>
date Thu, 20 Jan 2011 17:24:59 -0500
parents 57632dea2446
children
comparison
equal deleted inserted replaced
11585:1473d0cf86d2 11586:12df7854fa7c
30 30
31 #include "regex-match.h" 31 #include "regex-match.h"
32 #include "str-vec.h" 32 #include "str-vec.h"
33 #include "oct-locbuf.h" 33 #include "oct-locbuf.h"
34 34
35 regex_match& 35 regex_match&
36 regex_match::operator = (const regex_match& gm) 36 regex_match::operator = (const regex_match& gm)
37 { 37 {
38 if (this != &gm) 38 if (this != &gm)
39 { 39 {
40 #if HAVE_REGEX 40 #if HAVE_REGEX
57 delete [] compiled; 57 delete [] compiled;
58 #endif 58 #endif
59 } 59 }
60 60
61 61
62 void 62 void
63 regex_match::set_pattern (const std::string& p) 63 regex_match::set_pattern (const std::string& p)
64 { 64 {
65 #if HAVE_REGEX 65 #if HAVE_REGEX
66 for (int i = 0; i < pat.length (); i++) 66 for (int i = 0; i < pat.length (); i++)
67 regfree (compiled +i); 67 regfree (compiled +i);
68 delete [] compiled; 68 delete [] compiled;
69 #endif 69 #endif
70 pat = p; 70 pat = p;
71 init (); 71 init ();
72 } 72 }
73 73
74 void 74 void
75 regex_match::set_pattern (const string_vector& p) 75 regex_match::set_pattern (const string_vector& p)
76 { 76 {
77 #if HAVE_REGEX 77 #if HAVE_REGEX
78 for (int i = 0; i < pat.length (); i++) 78 for (int i = 0; i < pat.length (); i++)
79 regfree (compiled +i); 79 regfree (compiled +i);
80 delete [] compiled; 80 delete [] compiled;
81 #endif 81 #endif
82 pat = p; 82 pat = p;
83 init (); 83 init ();
84 } 84 }
85 85
86 void 86 void
87 regex_match::init (void) 87 regex_match::init (void)
93 93
94 compiled = new regex_t [npat]; 94 compiled = new regex_t [npat];
95 95
96 for (i = 0; i < npat; i++) 96 for (i = 0; i < npat; i++)
97 { 97 {
98 err = regcomp (compiled + i, pat(i).c_str (), 98 err = regcomp (compiled + i, pat(i).c_str (),
99 (REG_NOSUB | REG_EXTENDED | 99 (REG_NOSUB | REG_EXTENDED |
100 (case_insen ? REG_ICASE : 0))); 100 (case_insen ? REG_ICASE : 0)));
101 if (err) 101 if (err)
102 break; 102 break;
103 } 103 }
104 104
105 if (err) 105 if (err)
106 { 106 {
107 int len = regerror (err, compiled + i, 0, 0); 107 int len = regerror (err, compiled + i, 0, 0);
108 OCTAVE_LOCAL_BUFFER (char, errmsg, len); 108 OCTAVE_LOCAL_BUFFER (char, errmsg, len);
109 regerror(err, compiled + i, errmsg, len); 109 regerror(err, compiled + i, errmsg, len);
110 (*current_liboctave_error_handler) ("%s in pattern (%s)", errmsg, 110 (*current_liboctave_error_handler) ("%s in pattern (%s)", errmsg,
111 pat(i).c_str()); 111 pat(i).c_str());
112 112
113 for (int j = 0; j < i + 1; j++) 113 for (int j = 0; j < i + 1; j++)
114 regfree (compiled + j); 114 regfree (compiled + j);
115 } 115 }
116 #else 116 #else
117 (*current_liboctave_error_handler) 117 (*current_liboctave_error_handler)
118 ("regex not available in this version of Octave"); 118 ("regex not available in this version of Octave");
119 #endif 119 #endif
120 } 120 }
121 121
122 bool 122 bool
123 regex_match::match (const std::string& s) 123 regex_match::match (const std::string& s)
126 int npat = pat.length (); 126 int npat = pat.length ();
127 127
128 const char *str = s.c_str (); 128 const char *str = s.c_str ();
129 129
130 for (int i = 0; i < npat; i++) 130 for (int i = 0; i < npat; i++)
131 if (regexec (compiled + i, str, 0, 0, 0) == 0) 131 if (regexec (compiled + i, str, 0, 0, 0) == 0)
132 return true; 132 return true;
133 #endif 133 #endif
134 134
135 return false; 135 return false;
136 } 136 }