Skip to content

Commit

Permalink
Replace hoc_regexp_* by std::regex (#2694)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Cornu authored Jan 30, 2024
1 parent ed0b461 commit a710366
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 476 deletions.
1 change: 0 additions & 1 deletion cmake/NeuronFileLists.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ set(OC_FILE_LIST
ocerf.cpp
plot.cpp
plt.cpp
regexp.cpp
scoprand.cpp
settext.cpp
symbol.cpp
Expand Down
46 changes: 39 additions & 7 deletions src/nrnoc/cabcode.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#include <../../nrnconf.h>
/* /local/src/master/nrn/src/nrnoc/cabcode.cpp,v 1.37 1999/07/08 14:24:59 hines Exp */

#define HOC_L_LIST 1
#include <regex>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define HOC_L_LIST 1
#include "section.h"
#include "nrn_ansi.h"
#include "nrniv_mf.h"
Expand All @@ -13,6 +15,36 @@
#include "hocparse.h"
#include "membdef.h"

static char* escape_bracket(const char* s) {
static char* b;
const char* p1;
char* p2;
if (!b) {
b = new char[256];
}
for (p1 = s, p2 = b; *p1; ++p1, ++p2) {
switch (*p1) {
case '<':
*p2 = '[';
break;
case '>':
*p2 = ']';
break;
case '[':
case ']':
*p2 = '\\';
*(++p2) = *p1;
break;
default:
*p2 = *p1;
break;
}
}
*p2 = '\0';
return b;
}


extern int hoc_execerror_messages;
#define symlist hoc_symlist

Expand Down Expand Up @@ -1979,8 +2011,8 @@ void forall_section(void) {
Section* sec = hocSEC(qsec);
qsec = qsec->next;
if (buf[0]) {
hoc_regexp_compile(buf);
if (!hoc_regexp_search(secname(sec))) {
std::regex pattern(escape_bracket(buf));
if (!std::regex_match(secname(sec), pattern)) {
continue;
}
}
Expand Down Expand Up @@ -2011,17 +2043,17 @@ void hoc_ifsec(void) {

s = hoc_strpop();
Sprintf(buf, ".*%s.*", *s);
hoc_regexp_compile(buf);
if (hoc_regexp_search(secname(chk_access()))) {
std::regex pattern(escape_bracket(buf));
if (std::regex_match(secname(chk_access()), pattern)) {
hoc_execute(relative(savepc));
}
if (!hoc_returning)
pc = relative(savepc + 1);
}

void issection(void) { /* returns true if string is the access section */
hoc_regexp_compile(gargstr(1));
if (hoc_regexp_search(secname(chk_access()))) {
std::regex pattern(escape_bracket(gargstr(1)));
if (std::regex_match(secname(chk_access()), pattern)) {
hoc_retpushx(1.);
} else {
hoc_retpushx(0.);
Expand Down
2 changes: 0 additions & 2 deletions src/oc/oc_ansi.h
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,6 @@ int is_vector_arg(int);
char* vector_get_label(IvocVect*);
void vector_set_label(IvocVect*, char*);

void hoc_regexp_compile(const char*);
int hoc_regexp_search(const char*);
Symbol* hoc_install_var(const char*, double*);
void hoc_class_registration();
void hoc_spinit();
Expand Down
Loading

0 comments on commit a710366

Please sign in to comment.