From 3d4793044680eb0e9cf91792e916bbafca44c7a5 Mon Sep 17 00:00:00 2001 From: Anneli Schulz Date: Mon, 3 Feb 2014 15:31:47 +0100 Subject: [PATCH] corrected read method in region classes ( following the write ealier) --- src/sky/GSkyRegionCircle.cpp | 26 ++++++++++++++------------ src/sky/GSkyRegionRing.cpp | 26 ++++++++++++++------------ 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/src/sky/GSkyRegionCircle.cpp b/src/sky/GSkyRegionCircle.cpp index 3bf8705..2d380e1 100644 --- a/src/sky/GSkyRegionCircle.cpp +++ b/src/sky/GSkyRegionCircle.cpp @@ -347,18 +347,20 @@ void GSkyRegionCircle::read(const std::string& line) compute_solid_angle(); // Check if there is a given name for the region and set it - std::vectorcomments = gammalib::split(comment, " "); - for (int i = 0; i < comments.size(); i++) { - if (gammalib::contains(comments[i], "text")) { - std::vector attributes = gammalib::split(comments[i], "="); - if (attributes.size() < 2) { - std::string msg = - "Invalid character sequence encountered in provided" - " string \""+line+"\".\n" - "An attribute of the type \"text=Name\" is expected."; - throw GException::invalid_value(G_READ, msg); - } - m_name = attributes[1]; + std::vectorcomments = gammalib::split(comment, " "); + for (int i = 0; i < comments.size(); i++) { + if (gammalib::contains(comments[i], "text")) { + std::vector attributes = gammalib::split(comments[i], "="); + unsigned pos_text = attributes[1].find("{"); + unsigned length_text = attributes[1].find("}") - pos_text; + if (attributes.size() < 2) { + std::string msg = + "Invalid character sequence encountered in provided" + " string \""+line+"\".\n" + "An attribute of the type \"text=Name\" is expected."; + throw GException::invalid_value(G_READ, msg); + } + m_name = attributes[1].substr(pos_text+1, length_text-1); } } diff --git a/src/sky/GSkyRegionRing.cpp b/src/sky/GSkyRegionRing.cpp index c835486..6125103 100644 --- a/src/sky/GSkyRegionRing.cpp +++ b/src/sky/GSkyRegionRing.cpp @@ -372,18 +372,20 @@ void GSkyRegionRing::read(const std::string& line) compute_solid_angle(); // Check if there is a given name for the region and set it - std::vectorcomments = gammalib::split(comment, " "); - for (int i = 0; i < comments.size(); i++) { - if (gammalib::contains(comments[i], "text")) { - std::vector attributes = gammalib::split(comments[i], "="); - if (attributes.size() < 2) { - std::string msg = - "Invalid character sequence encountered in provided" - " string \""+line+"\".\n" - "An attribute of the type \"text=Name\" is expected."; - throw GException::invalid_value(G_READ, msg); - } - m_name = attributes[1]; + std::vectorcomments = gammalib::split(comment, " "); + for (int i = 0; i < comments.size(); i++) { + if (gammalib::contains(comments[i], "text")) { + std::vector attributes = gammalib::split(comments[i], "="); + unsigned pos_text = attributes[1].find("{"); + unsigned length_text = attributes[1].find("}") - pos_text; + if (attributes.size() < 2) { + std::string msg = + "Invalid character sequence encountered in provided" + " string \""+line+"\".\n" + "An attribute of the type \"text=Name\" is expected."; + throw GException::invalid_value(G_READ, msg); + } + m_name = attributes[1].substr(pos_text+1, length_text-1); } } -- libgit2 0.21.4