diff --git a/source/adios2/helper/adiosString.cpp b/source/adios2/helper/adiosString.cpp index a75799e838491937053454f3822251470cc26dd3..7ef54bdde13deaf22b16f2ee9b4ba2570c1d07c7 100644 --- a/source/adios2/helper/adiosString.cpp +++ b/source/adios2/helper/adiosString.cpp @@ -20,15 +20,13 @@ namespace adios2 { -std::string FileToString(const std::string &fileName) +std::string FileToString(const std::string &fileName) noexcept { std::ifstream fileStream(fileName); if (!fileStream) { - throw std::invalid_argument( - "ERROR: file " + fileName + - " could not be opened. Check permissions or existence\n"); + return std::string(); // empty string } std::ostringstream fileSS; diff --git a/source/adios2/helper/adiosString.h b/source/adios2/helper/adiosString.h index 3c06da6b006fb52fb8cddcf762b475738ec4b64b..c89c87e5bfaf0f0c2b6eb5f4af5bb02653703aff 100644 --- a/source/adios2/helper/adiosString.h +++ b/source/adios2/helper/adiosString.h @@ -27,7 +27,7 @@ namespace adios2 * @param fileName of text file * @return file contents in a string */ -std::string FileToString(const std::string &fileName); +std::string FileToString(const std::string &fileName) noexcept; /** * Transforms a vector to a map of parameters diff --git a/source/adios2/helper/adiosXML.cpp b/source/adios2/helper/adiosXML.cpp index a49b0c5ab40ff75864240aa243de05edf6e1d0dd..79f1c48a31746e96324d0a00470e639bd97e604e 100644 --- a/source/adios2/helper/adiosXML.cpp +++ b/source/adios2/helper/adiosXML.cpp @@ -196,11 +196,13 @@ Params GetTagAttributesXML(const std::string &tagHeader) auto lf_GetAttributes = [&](const std::string &tag) -> Params { Params attributes; std::string currentTag(tag.substr(tag.find_first_of(" \t\n"))); + std::string::size_type currentPosition(0); - while (currentTag.find('=') != currentTag.npos) // equalPosition + while (currentTag.find('=', currentPosition) != + currentTag.npos) // equalPosition { - currentTag = - currentTag.substr(currentTag.find_first_not_of(" \t\n")); + currentTag = currentTag.substr( + currentTag.find_first_not_of(" \t\n", currentPosition)); auto equalPosition = currentTag.find('='); if (currentTag.size() <= equalPosition + 1) { @@ -210,20 +212,28 @@ Params GetTagAttributesXML(const std::string &tagHeader) "in call to ADIOS constructor\n"); } - const std::string key(currentTag.substr(0, equalPosition)); + std::string key(currentTag.substr(0, equalPosition)); + key.erase(key.find_last_not_of(" \t\n") + 1); + std::string value; - const char quote = currentTag[equalPosition + 1]; + auto quotePosition = + currentTag.find_first_not_of(" \t\n", equalPosition + 1); + + const char quote = currentTag.at(quotePosition); if (quote == '\'' || quote == '"') { - value = lf_GetQuotedValue(quote, equalPosition + 1, currentTag); + value = lf_GetQuotedValue(quote, quotePosition, currentTag); } else { - // throw exception here? + throw std::invalid_argument( + "ERROR: quote must be \" or ' in XML config tag " + tag + + ", in call to ADIOS constructor"); } attributes.emplace(key, value); + currentPosition = quotePosition + value.size() + 1; } return attributes; }; @@ -262,6 +272,12 @@ void InitXML(const std::string configXML, const MPI_Comm mpiComm, { // independent IO std::string fileContents(FileToString(configXML)); + if (fileContents.empty()) + { + // issue a warning? + return; + } + RemoveCommentsXML(fileContents); // adios-config