# HG changeset patch # User Sebastien Jodogne # Date 1689144496 -7200 # Node ID 1c95010d9d2e7e1cde90bb2041424906d0460e4b # Parent c766c25fe4929d56e98d73025c76453442e1162f clarification by removing regular expressions diff -r c766c25fe492 -r 1c95010d9d2e ViewerPlugin/IIIF.cpp --- a/ViewerPlugin/IIIF.cpp Wed Jul 12 08:40:59 2023 +0200 +++ b/ViewerPlugin/IIIF.cpp Wed Jul 12 08:48:16 2023 +0200 @@ -32,7 +32,6 @@ #include #include -#include #include @@ -224,48 +223,36 @@ } else { - int regionX, regionY, regionWidth, regionHeight; + std::vector tokens; + Orthanc::Toolbox::TokenizeString(tokens, region, ','); + + uint32_t regionX, regionY, regionWidth, regionHeight; - bool ok = false; - boost::regex regionPattern("([0-9]+),([0-9]+),([0-9]+),([0-9]+)"); - boost::cmatch regionWhat; - if (regex_match(region.c_str(), regionWhat, regionPattern)) - { - try - { - regionX = boost::lexical_cast(regionWhat[1]); - regionY = boost::lexical_cast(regionWhat[2]); - regionWidth = boost::lexical_cast(regionWhat[3]); - regionHeight = boost::lexical_cast(regionWhat[4]); - ok = (regionX >= 0 && - regionY >= 0 && - regionWidth > 0 && - regionHeight > 0); - } - catch (boost::bad_lexical_cast&) - { - } - } - - if (!ok) + if (tokens.size() != 4 || + !Orthanc::SerializationToolbox::ParseUnsignedInteger32(regionX, tokens[0]) || + !Orthanc::SerializationToolbox::ParseUnsignedInteger32(regionY, tokens[1]) || + !Orthanc::SerializationToolbox::ParseUnsignedInteger32(regionWidth, tokens[2]) || + !Orthanc::SerializationToolbox::ParseUnsignedInteger32(regionHeight, tokens[3])) { throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented, "IIIF - Not a (x,y,width,height) region, found: " + region); } - ok = false; - int cropWidth, cropHeight; - boost::regex sizePattern("([0-9]+),([0-9]+)"); - boost::cmatch sizeWhat; - if (regex_match(size.c_str(), sizeWhat, sizePattern)) + uint32_t cropWidth, cropHeight; + + Orthanc::Toolbox::TokenizeString(tokens, size, ','); + + bool ok = false; + if (tokens.size() == 2 && + Orthanc::SerializationToolbox::ParseUnsignedInteger32(cropWidth, tokens[0])) { - try + if (tokens[1].empty()) { - cropWidth = boost::lexical_cast(sizeWhat[1]); - cropHeight = boost::lexical_cast(sizeWhat[2]); - ok = (cropWidth > 0 && cropHeight > 0); + cropHeight = cropWidth; + ok = true; } - catch (boost::bad_lexical_cast&) + else if (Orthanc::SerializationToolbox::ParseUnsignedInteger32(cropHeight, tokens[1])) { + ok = true; } }