Skip to content

Commit

Permalink
Remove usage of IVOS/regexp (#2204)
Browse files Browse the repository at this point in the history
Replace with `std::regex`

Co-authored-by: Michael Hines <michael.hines@yale.edu>
Co-authored-by: Pramod Kumbhar <pramod.s.kumbhar@gmail.com>
  • Loading branch information
3 people committed Jan 27, 2024
1 parent c1e245d commit 128c684
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 1,408 deletions.
2 changes: 1 addition & 1 deletion cmake/NeuronFileLists.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ set(NMODL_FILES_LIST
units.cpp
version.cpp)

set(IVOS_FILES_LIST observe.cpp regexp.cpp resource.cpp)
set(IVOS_FILES_LIST observe.cpp resource.cpp)

set(MPI_DYNAMIC_INCLUDE nrnmpi_dynam.h nrnmpi_dynam_cinc nrnmpi_dynam_wrappers.inc)

Expand Down
2 changes: 1 addition & 1 deletion share/lib/hoc/import3d/read_nlcda3.hoc
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ proc b2soption_split() {local i, n, id, ip localobj p, newsec, tobj
}

proc remove_trailspace() { // yuck
hoc_sf_.head(line, " *$", line)
hoc_sf_.rtrim(line, line)
sprint(line, "%s\n", line)
}

Expand Down
57 changes: 39 additions & 18 deletions src/ivoc/strfun.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include <../../nrnconf.h>
#include <InterViews/regexp.h>
#include <stdio.h>
#include <stdlib.h>
#include "classreg.h"
#include "oc2iv.h"
#include <string.h>
#include <regex>
// for alias
#include <symdir.h>
#include <oclist.h>
Expand Down Expand Up @@ -39,31 +39,52 @@ static double l_len(void*) {

static double l_head(void*) {
std::string text(gargstr(1));
Regexp r(gargstr(2));
r.Search(text.c_str(), text.size(), 0, text.size());
int i = r.BeginningOfMatch();
// text.set_to_left(i); doesnt work
char** head = hoc_pgargstr(3);
if (i > 0) {
hoc_assign_str(head, text.substr(0, i).c_str());
} else {
hoc_assign_str(head, "");
{ // Clean the text so we keep only the first line
// Imitation of std::multiline in our case
std::regex r("^(.*)(\n|$)");
std::smatch sm;
std::regex_search(text, sm, r);
text = sm[1];
}
int i = -1;
std::string result{};
try {
std::regex r(gargstr(2), std::regex::egrep);
if (std::smatch sm; std::regex_search(text, sm, r)) {
i = sm.position();
result = sm.prefix().str();
}
} catch (const std::regex_error& e) {
std::cerr << e.what() << std::endl;
}
char** head = hoc_pgargstr(3);
hoc_assign_str(head, result.c_str());
hoc_return_type_code = 1; // integer
return double(i);
}

static double l_tail(void*) {
std::string text(gargstr(1));
Regexp r(gargstr(2));
r.Search(text.c_str(), text.size(), 0, text.size());
int i = r.EndOfMatch();
char** tail = hoc_pgargstr(3);
if (i >= 0) {
hoc_assign_str(tail, text.c_str() + i);
} else {
hoc_assign_str(tail, "");
{ // Clean the text so we keep only the first line
// Imitation of std::multiline in our case
std::regex r("^(.*)(\n|$)");
std::smatch sm;
std::regex_search(text, sm, r);
text = sm[1];
}
int i = -1;
std::string result{};
try {
std::regex r(gargstr(2), std::regex::egrep);
if (std::smatch sm; std::regex_search(text, sm, r)) {
i = sm.position() + sm.length();
result = sm.suffix().str();
}
} catch (const std::regex_error& e) {
std::cerr << e.what() << std::endl;
}
char** tail = hoc_pgargstr(3);
hoc_assign_str(tail, result.c_str());
hoc_return_type_code = 1; // integer
return double(i);
}
Expand Down
1 change: 0 additions & 1 deletion src/ivos/InterViews/_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@
#define Raster _lib_iv(Raster)
#define RasterRep _lib_iv(RasterRep)
#define Reducer _lib_iv(Reducer)
#define Regexp _lib_iv(Regexp)
#define ReqErr _lib_iv(ReqErr)
#define Requirement _lib_iv(Requirement)
#define Requisition _lib_iv(Requisition)
Expand Down
1 change: 0 additions & 1 deletion src/ivos/InterViews/_undefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@
#undef Raster
#undef RasterRep
#undef Reducer
#undef Regexp
#undef ReqErr
#undef Requirement
#undef Requisition
Expand Down
80 changes: 0 additions & 80 deletions src/ivos/InterViews/regexp.h

This file was deleted.

Loading

0 comments on commit 128c684

Please sign in to comment.