Skip to content

Commit

Permalink
replace boost::regex with std::regex
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Wittgen committed Jun 11, 2021
1 parent 7f68a11 commit d0074a6
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 28 deletions.
24 changes: 12 additions & 12 deletions src/fits.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
#include <unordered_set>
#include <unordered_map>
#include <filesystem>
#include <regex>

#include "fitsio.h"
extern "C" {
#include "fitsio2.h"
}

#include "boost/algorithm/string.hpp"
#include "boost/regex.hpp"
#include "boost/preprocessor/seq/for_each.hpp"
#include "boost/format.hpp"

Expand Down Expand Up @@ -915,24 +915,24 @@ class MetadataIterationFunctor : public HeaderIterationFunctor {

void MetadataIterationFunctor::operator()(std::string const &key, std::string const &value,
std::string const &comment) {
static boost::regex const boolRegex("[tTfF]");
static boost::regex const intRegex("[+-]?[0-9]+");
static boost::regex const doubleRegex("[+-]?([0-9]*\\.?[0-9]+|[0-9]+\\.?[0-9]*)([eE][+-]?[0-9]+)?");
static boost::regex const fitsStringRegex("'(.*?) *'");
static std::regex const boolRegex("[tTfF]");
static std::regex const intRegex("[+-]?[0-9]+");
static std::regex const doubleRegex("[+-]?([0-9]*\\.?[0-9]+|[0-9]+\\.?[0-9]*)([eE][+-]?[0-9]+)?");
static std::regex const fitsStringRegex("'(.*?) *'");
// regex for two-line comment added to all FITS headers by CFITSIO
static boost::regex const fitsDefinitionCommentRegex(
static std::regex const fitsDefinitionCommentRegex(
" *(FITS \\(Flexible Image Transport System\\)|and Astrophysics', volume 376, page 359).*");
boost::smatch matchStrings;
std::smatch matchStrings;

if (strip && isKeyIgnored(key)) {
return;
}

std::istringstream converter(value);
if (boost::regex_match(value, boolRegex)) {
if (std::regex_match(value, boolRegex)) {
// convert the string to an bool
add(key, bool(value == "T" || value == "t"), comment);
} else if (boost::regex_match(value, intRegex)) {
} else if (std::regex_match(value, intRegex)) {
// convert the string to an int
std::int64_t val;
converter >> val;
Expand All @@ -941,12 +941,12 @@ void MetadataIterationFunctor::operator()(std::string const &key, std::string co
} else {
add(key, val, comment);
}
} else if (boost::regex_match(value, doubleRegex)) {
} else if (std::regex_match(value, doubleRegex)) {
// convert the string to a double
double val;
converter >> val;
add(key, val, comment);
} else if (boost::regex_match(value, matchStrings, fitsStringRegex)) {
} else if (std::regex_match(value, matchStrings, fitsStringRegex)) {
std::string const str = matchStrings[1].str(); // strip off the enclosing single quotes
double val = stringToNonFiniteDouble(str);
if (val != 0.0) {
Expand All @@ -956,7 +956,7 @@ void MetadataIterationFunctor::operator()(std::string const &key, std::string co
}
} else if (key == "HISTORY") {
add(key, comment, "");
} else if (key == "COMMENT" && !(strip && boost::regex_match(comment, fitsDefinitionCommentRegex))) {
} else if (key == "COMMENT" && !(strip && std::regex_match(comment, fitsDefinitionCommentRegex))) {
add(key, comment, "");
} else if (key.empty() && value.empty()) {
// This is a blank keyword comment. Since comments do not retain
Expand Down
1 change: 0 additions & 1 deletion src/image/MaskedImage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-variable"
#pragma clang diagnostic pop
#include "boost/regex.hpp"
#include "boost/format.hpp"
#include "lsst/log/Log.h"
#include "lsst/pex/exceptions.h"
Expand Down
8 changes: 4 additions & 4 deletions src/math/warpExposure.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
#include <vector>
#include <utility>
#include <ctime>
#include <regex>

#include <memory>
#include "boost/pointer_cast.hpp"
#include "boost/regex.hpp"
#include "astshim.h"

#include "lsst/log/Log.h"
Expand Down Expand Up @@ -160,11 +160,11 @@ std::string NearestWarpingKernel::NearestFunction1::toString(std::string const &

std::shared_ptr<SeparableKernel> makeWarpingKernel(std::string name) {
typedef std::shared_ptr<SeparableKernel> KernelPtr;
boost::cmatch matches;
static const boost::regex LanczosRE("lanczos(\\d+)");
std::cmatch matches;
static const std::regex LanczosRE("lanczos(\\d+)");
if (name == "bilinear") {
return KernelPtr(new BilinearWarpingKernel());
} else if (boost::regex_match(name.c_str(), matches, LanczosRE)) {
} else if (std::regex_match(name.c_str(), matches, LanczosRE)) {
std::string orderStr(matches[1].first, matches[1].second);
int order;
std::istringstream(orderStr) >> order;
Expand Down
20 changes: 10 additions & 10 deletions src/table/io/FitsSchemaInputMapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#include <string>
#include <algorithm>
#include <cctype>
#include <regex>

#include "boost/regex.hpp"
#include "boost/multi_index_container.hpp"
#include "boost/multi_index/sequenced_index.hpp"
#include "boost/multi_index/ordered_index.hpp"
Expand Down Expand Up @@ -278,9 +278,9 @@ FitsSchemaInputMapper::FitsSchemaInputMapper(daf::base::PropertyList &metadata,
// Regex to unpack a FITS TFORM value for a bit array column (TFORM code 'X'). The number
// that precedes the code is the size of the array; the number that follows it (if present)
// is ignored.
static boost::regex const regex("(\\d+)?X\\(?(\\d)*\\)?", boost::regex::perl);
boost::smatch m;
if (!boost::regex_match(iter->tform, m, regex)) {
static std::regex const regex("(\\d+)?X\\(?(\\d)*\\)?");
std::smatch m;
if (!std::regex_match(iter->tform, m, regex)) {
throw LSST_EXCEPT(
afw::fits::FitsError,
(boost::format("Invalid TFORM key for flags column: '%s'") % iter->tform).str());
Expand Down Expand Up @@ -585,9 +585,9 @@ template <typename T, int N>
class CovarianceConversionReader : public FitsColumnReader {
public:
static std::string guessUnits(std::string const &oldUnits) {
static boost::regex const regex("(.*)(\\^(\\d+))?", boost::regex::perl);
boost::smatch m;
if (!boost::regex_match(oldUnits, m, regex)) {
static std::regex const regex("(.*)(\\\\^(\\d+))?");
std::smatch m;
if (!std::regex_match(oldUnits, m, regex)) {
int oldPower = std::stoi(m[2]);
int newPower = std::sqrt(oldPower);
return std::to_string(newPower);
Expand Down Expand Up @@ -628,10 +628,10 @@ std::unique_ptr<FitsColumnReader> makeColumnReader(Schema &schema, FitsSchemaIte
// Regex to unpack a FITS TFORM value. The first number is the size of the array (1 if not present),
// followed by an alpha code indicating the type (preceded by P or Q for variable size array).
// The last number is ignored.
static boost::regex const regex("(\\d+)?([PQ])?(\\u)\\(?(\\d)*\\)?", boost::regex::perl);
static std::regex const regex("(\\d+)?([PQ])?([A-Z])\\(?(\\d)*\\)?");
// start by parsing the format; this tells the element type of the field and the number of elements
boost::smatch m;
if (!boost::regex_match(item.tform, m, regex)) {
std::smatch m;
if (!std::regex_match(item.tform, m, regex)) {
return std::unique_ptr<FitsColumnReader>();
}
int size = 1;
Expand Down
2 changes: 1 addition & 1 deletion ups/afw.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import lsst.sconsUtils
dependencies = {
"required": ["utils", "daf_persistence", "daf_base", "pex_exceptions", "geom", "log", "pex_config",
"eigen", "fftw", "ndarray", "numpy", "minuit2", "gsl", "cfitsio",
"boost_regex", "astshim", "sphgeom"],
"astshim", "sphgeom"],
"buildRequired": ["boost_test", "boost_timer", "pybind11"],
}

Expand Down

0 comments on commit d0074a6

Please sign in to comment.