diff --git a/src/classes/PStartupHandler.cpp b/src/classes/PStartupHandler.cpp index 47bb48ca2..7907e0ecf 100644 --- a/src/classes/PStartupHandler.cpp +++ b/src/classes/PStartupHandler.cpp @@ -34,13 +34,12 @@ #include #include -#include -#include #include #include #include #include "PStartupHandler.h" +#include "PStringUtils.h" ClassImpQ(PStartupHandler) @@ -451,8 +450,6 @@ void PStartupHandler::OnEndElement(const Char_t *str) */ void PStartupHandler::OnCharacters(const Char_t *str) { - TObjArray *tokens; - TObjString *ostr; TString tstr; Int_t color, r, g, b, ival; @@ -481,60 +478,44 @@ void PStartupHandler::OnCharacters(const Char_t *str) } break; case eColor: - // check that str is a rbg code - tstr = TString(str); - tokens = tstr.Tokenize(","); - // check that there any tokens - if (!tokens) { - std::cerr << std::endl << "PStartupHandler **WARNING** '" << str << "' is not a rbg code, will ignore it"; - std::cerr << std::endl; - return; + { + // check that str is a rbg code + std::vector rgb = PStringUtils::Split(str, ","); + // check there is the right number of tokens + if (rgb.size() != 3) { + std::cerr << std::endl << "PStartupHandler **WARNING** '" << str << "' is not a rbg code, will ignore it"; + std::cerr << std::endl; + return; + } + // get r + if (PStringUtils::IsInt(rgb[0])) { + r = PStringUtils::ToInt(rgb[0]); + } else { + std::cerr << std::endl << "PStartupHandler **WARNING** r within the rgb code is not a number, will ignore it"; + std::cerr << std::endl; + return; + } + // get g + if (PStringUtils::IsInt(rgb[1])) { + g = PStringUtils::ToInt(rgb[1]); + } else { + std::cerr << std::endl << "PStartupHandler **WARNING** g within the rgb code is not a number, will ignore it"; + std::cerr << std::endl; + return; + } + // get b + if (PStringUtils::IsInt(rgb[2])) { + b = PStringUtils::ToInt(rgb[2]); + } else { + std::cerr << std::endl << "PStartupHandler **WARNING** b within the rgb code is not a number, will ignore it"; + std::cerr << std::endl; + return; + } + // generate the ROOT color code based on str + color = TColor::GetColor(r,g,b); + // add the color code to the color list + fColorList.push_back(color); } - // check there is the right number of tokens - if (tokens->GetEntries() != 3) { - std::cerr << std::endl << "PStartupHandler **WARNING** '" << str << "' is not a rbg code, will ignore it"; - std::cerr << std::endl; - return; - } - // get r - ostr = dynamic_cast(tokens->At(0)); - tstr = ostr->GetString(); - if (tstr.IsDigit()) { - r = tstr.Atoi(); - } else { - std::cerr << std::endl << "PStartupHandler **WARNING** r within the rgb code is not a number, will ignore it"; - std::cerr << std::endl; - return; - } - // get g - ostr = dynamic_cast(tokens->At(1)); - tstr = ostr->GetString(); - if (tstr.IsDigit()) { - g = tstr.Atoi(); - } else { - std::cerr << std::endl << "PStartupHandler **WARNING** g within the rgb code is not a number, will ignore it"; - std::cerr << std::endl; - return; - } - // get b - ostr = dynamic_cast(tokens->At(2)); - tstr = ostr->GetString(); - if (tstr.IsDigit()) { - b = tstr.Atoi(); - } else { - std::cerr << std::endl << "PStartupHandler **WARNING** b within the rgb code is not a number, will ignore it"; - std::cerr << std::endl; - return; - } - // clean up tokens - if (tokens) { - delete tokens; - tokens = nullptr; - } - // generate the ROOT color code based on str - color = TColor::GetColor(r,g,b); - // add the color code to the color list - fColorList.push_back(color); break; case eUnits: tstr = TString(str);