Commit 3d4793044680eb0e9cf91792e916bbafca44c7a5

Authored by Anneli Schulz
1 parent a54bef38

corrected read method in region classes ( following the write ealier)

src/sky/GSkyRegionCircle.cpp
@@ -347,18 +347,20 @@ void GSkyRegionCircle::read(const std::string& line) @@ -347,18 +347,20 @@ void GSkyRegionCircle::read(const std::string& line)
347 compute_solid_angle(); 347 compute_solid_angle();
348 348
349 // Check if there is a given name for the region and set it 349 // Check if there is a given name for the region and set it
350 - std::vector<std::string>comments = gammalib::split(comment, " ");  
351 - for (int i = 0; i < comments.size(); i++) {  
352 - if (gammalib::contains(comments[i], "text")) {  
353 - std::vector<std::string> attributes = gammalib::split(comments[i], "=");  
354 - if (attributes.size() < 2) {  
355 - std::string msg =  
356 - "Invalid character sequence encountered in provided"  
357 - " string \""+line+"\".\n"  
358 - "An attribute of the type \"text=Name\" is expected.";  
359 - throw GException::invalid_value(G_READ, msg);  
360 - }  
361 - m_name = attributes[1]; 350 + std::vector<std::string>comments = gammalib::split(comment, " ");
  351 + for (int i = 0; i < comments.size(); i++) {
  352 + if (gammalib::contains(comments[i], "text")) {
  353 + std::vector<std::string> attributes = gammalib::split(comments[i], "=");
  354 + unsigned pos_text = attributes[1].find("{");
  355 + unsigned length_text = attributes[1].find("}") - pos_text;
  356 + if (attributes.size() < 2) {
  357 + std::string msg =
  358 + "Invalid character sequence encountered in provided"
  359 + " string \""+line+"\".\n"
  360 + "An attribute of the type \"text=Name\" is expected.";
  361 + throw GException::invalid_value(G_READ, msg);
  362 + }
  363 + m_name = attributes[1].substr(pos_text+1, length_text-1);
362 } 364 }
363 } 365 }
364 366
src/sky/GSkyRegionRing.cpp
@@ -372,18 +372,20 @@ void GSkyRegionRing::read(const std::string&amp; line) @@ -372,18 +372,20 @@ void GSkyRegionRing::read(const std::string&amp; line)
372 compute_solid_angle(); 372 compute_solid_angle();
373 373
374 // Check if there is a given name for the region and set it 374 // Check if there is a given name for the region and set it
375 - std::vector<std::string>comments = gammalib::split(comment, " ");  
376 - for (int i = 0; i < comments.size(); i++) {  
377 - if (gammalib::contains(comments[i], "text")) {  
378 - std::vector<std::string> attributes = gammalib::split(comments[i], "=");  
379 - if (attributes.size() < 2) {  
380 - std::string msg =  
381 - "Invalid character sequence encountered in provided"  
382 - " string \""+line+"\".\n"  
383 - "An attribute of the type \"text=Name\" is expected.";  
384 - throw GException::invalid_value(G_READ, msg);  
385 - }  
386 - m_name = attributes[1]; 375 + std::vector<std::string>comments = gammalib::split(comment, " ");
  376 + for (int i = 0; i < comments.size(); i++) {
  377 + if (gammalib::contains(comments[i], "text")) {
  378 + std::vector<std::string> attributes = gammalib::split(comments[i], "=");
  379 + unsigned pos_text = attributes[1].find("{");
  380 + unsigned length_text = attributes[1].find("}") - pos_text;
  381 + if (attributes.size() < 2) {
  382 + std::string msg =
  383 + "Invalid character sequence encountered in provided"
  384 + " string \""+line+"\".\n"
  385 + "An attribute of the type \"text=Name\" is expected.";
  386 + throw GException::invalid_value(G_READ, msg);
  387 + }
  388 + m_name = attributes[1].substr(pos_text+1, length_text-1);
387 } 389 }
388 } 390 }
389 391