Skip to content

Commit

Permalink
Fixed bug in getting named wildcards
Browse files Browse the repository at this point in the history
  • Loading branch information
nickgammon committed Apr 16, 2018
1 parent f99ffb2 commit 000a621
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 47 deletions.
41 changes: 0 additions & 41 deletions Utilities.cpp
Expand Up @@ -2558,47 +2558,6 @@ const char * Convert_PCRE_Runtime_Error (const int iError)
}
} // end of Convert_PCRE_Runtime_Error


/*************************************************
* Find first set of multiple named strings *
*************************************************/

// taken from pcre_get.c - with minor modifications

/* This function allows for duplicate names in the table of named substrings.
It returns the number of the first one that was set in a pattern match.
Arguments:
code the compiled regex
stringname the name of the capturing substring
ovector the vector of matched substrings
Returns: the number of the first that is set,
or the number of the last one if none are set,
or a negative number on error
*/

typedef unsigned char uschar;

int
njg_get_first_set(const pcre *code, const char *stringname, const int *ovector)
{
const real_pcre *re = (const real_pcre *)code;
int entrysize;
char *first, *last;
uschar *entry;
if ((re->options & (PCRE_DUPNAMES | PCRE_JCHANGED)) == 0)
return pcre_get_stringnumber(code, stringname);
entrysize = pcre_get_stringtable_entries(code, stringname, &first, &last);
if (entrysize <= 0) return entrysize;
for (entry = (uschar *)first; entry <= (uschar *)last; entry += entrysize)
{
int n = (entry[0] << 8) + entry[1];
if (ovector[n*2] >= 0) return n;
}
return (first[0] << 8) + first[1];
}

// i18n (Internationalization) stuff

// translate message (eg. "File cannot be opened") into locale-specific language
Expand Down
6 changes: 3 additions & 3 deletions regexp.cpp
Expand Up @@ -171,21 +171,21 @@ string t_regexp::GetWildcard (const string& sName) const

if (namecount > 0)
{
unsigned char *name_table;
int name_entry_size;
unsigned char *tabptr;
int ncapt;
int jchanged;
pcre_fullinfo(m_program, m_extra, PCRE_INFO_CAPTURECOUNT, &ncapt);
pcre_fullinfo(m_program, m_extra, PCRE_INFO_NAMETABLE, &name_table);
pcre_fullinfo(m_program, m_extra, PCRE_INFO_NAMETABLE, &tabptr);
pcre_fullinfo(m_program, m_extra, PCRE_INFO_NAMEENTRYSIZE, &name_entry_size);
pcre_fullinfo(m_program, m_extra, PCRE_INFO_JCHANGED, &jchanged);
tabptr = name_table;
set<string> found_strings;
for (int i = 0; i < namecount; i++, tabptr += name_entry_size)
{
int n = (tabptr[0] << 8) | tabptr[1];
const unsigned char * name = tabptr + 2;
if (strcmp (sName.c_str (), (LPCTSTR) name) != 0) // skip if wrong name
continue;
// if duplicates were possible then ...
if (jchanged)
{
Expand Down
3 changes: 0 additions & 3 deletions regexp.h
Expand Up @@ -20,9 +20,6 @@

#include "pcre\pcre.h"

// for duplicate named wildcards
int njg_get_first_set(const pcre *code, const char *stringname, const int *ovector);

// compiled regular expression type

class t_regexp
Expand Down

0 comments on commit 000a621

Please sign in to comment.