4
4
#include " MUSHclient.h"
5
5
#include " doc.h"
6
6
#include " dialogs\RegexpProblemDlg.h"
7
+ #include " pcre\config.h"
8
+ #include " pcre\pcre.h"
9
+ #include " pcre\pcre_internal.h"
7
10
8
11
#ifdef _DEBUG
9
12
#define new DEBUG_NEW
@@ -146,4 +149,70 @@ pcre * program;
146
149
dlg.m_iColumn = erroroffset + 1 ;
147
150
dlg.DoModal ();
148
151
return false ; // bad
149
- }
152
+ }
153
+
154
+
155
+ // returns a named wildcard
156
+ string t_regexp::GetWildcard (const string& sName ) const
157
+ {
158
+ int iNumber = PCRE_ERROR_NOSUBSTRING;
159
+ if (IsStringNumber (sName ))
160
+ iNumber = atoi (sName .c_str ());
161
+ else
162
+ {
163
+ if (m_program == NULL )
164
+ iNumber = PCRE_ERROR_NOSUBSTRING;
165
+ else
166
+ {
167
+ /* now do named subpatterns */
168
+ int namecount;
169
+ pcre_fullinfo (m_program, m_extra, PCRE_INFO_NAMECOUNT, &namecount);
170
+
171
+
172
+ if (namecount > 0 )
173
+ {
174
+ unsigned char *name_table;
175
+ int name_entry_size;
176
+ unsigned char *tabptr;
177
+ int ncapt;
178
+ int jchanged;
179
+ pcre_fullinfo (m_program, m_extra, PCRE_INFO_CAPTURECOUNT, &ncapt);
180
+ pcre_fullinfo (m_program, m_extra, PCRE_INFO_NAMETABLE, &name_table);
181
+ pcre_fullinfo (m_program, m_extra, PCRE_INFO_NAMEENTRYSIZE, &name_entry_size);
182
+ pcre_fullinfo (m_program, m_extra, PCRE_INFO_JCHANGED, &jchanged);
183
+ tabptr = name_table;
184
+ set<string> found_strings;
185
+ for (int i = 0 ; i < namecount; i++, tabptr += name_entry_size)
186
+ {
187
+ int n = (tabptr[0 ] << 8 ) | tabptr[1 ];
188
+ const unsigned char * name = tabptr + 2 ;
189
+ // if duplicates were possible then ...
190
+ if (jchanged)
191
+ {
192
+ // this code is to ensure that we don't find a match (eg. mob = Kobold)
193
+ // and then if duplicates were allowed, replace Kobold with false.
194
+
195
+ string sName = (LPCTSTR) name;
196
+
197
+ // for duplicate names, see if we already added this name
198
+ if (found_strings.find (sName ) != found_strings.end ())
199
+ {
200
+ // do not replace if this one is out of range or empty
201
+ if (n < 0 || n > m_iCount || GetWildcard (n) == " " )
202
+ continue ;
203
+ } // end of duplicate
204
+ else
205
+ found_strings.insert (sName );
206
+ }
207
+
208
+ if (n >= 0 && n <= m_iCount)
209
+ iNumber = n;
210
+
211
+ } // end of wildcard loop
212
+ } // end of having named wildcards
213
+
214
+ } // end of program not NULL
215
+
216
+ } // end of wanting a named wildcard
217
+ return GetWildcard (iNumber);
218
+ } // end of t_regexp::GetWildcard
0 commit comments