|
musrfit 1.10.0
|
Lightweight, dependency-free string utilities (pure C++17). More...
#include <PStringUtils.h>
Static Public Member Functions | |
| static std::vector< std::string > | Split (const std::string &str, const std::string &delimiters) |
| static bool | IsInt (const std::string &str) |
| static bool | IsFloat (const std::string &str) |
| static int | ToInt (const std::string &str, bool *ok=nullptr) |
| static double | ToDouble (const std::string &str, bool *ok=nullptr) |
| static bool | IsEqualNoCase (const std::string &a, const std::string &b) |
| static bool | ContainsNoCase (const std::string &haystack, const std::string &needle) |
| static bool | BeginsWithNoCase (const std::string &str, const std::string &prefix) |
Lightweight, dependency-free string utilities (pure C++17).
PStringUtils collects small string helpers used throughout the musrfit suite, in particular for tokenizing and parsing the plain-text MSR file format. The implementation deliberately relies only on the C++ standard library (no ROOT) so that it can be reused freely.
The provided helpers replicate the semantics of the corresponding ROOT TString methods that were previously used:
All methods are static; the class is a pure namespace-like utility.
Definition at line 56 of file PStringUtils.h.
|
static |
Case-insensitive prefix test. Mirrors TString::BeginsWith(..., TString::kIgnoreCase).
| str | string to be tested |
| prefix | prefix to be searched for |
Case-insensitive prefix test, mirroring TString::BeginsWith(..., TString::kIgnoreCase).
| str | string to be tested |
| prefix | prefix to be searched for |
Definition at line 265 of file PStringUtils.cpp.
Referenced by PMsrHandler::HandlePlotEntry().
|
static |
Case-insensitive substring search. Mirrors TString::Contains(..., TString::kIgnoreCase).
| haystack | string to be searched in |
| needle | substring to be searched for |
Case-insensitive substring search, mirroring TString::Contains(..., TString::kIgnoreCase).
| haystack | string to be searched in |
| needle | substring to be searched for |
Definition at line 235 of file PStringUtils.cpp.
Referenced by PMsrHandler::CheckFuncs(), PMsrHandler::CheckMaps(), and PMsrHandler::HandlePlotEntry().
|
static |
Case-insensitive full-string equality. Mirrors TString::CompareTo(..., TString::kIgnoreCase) == 0.
| a | first string |
| b | second string |
Case-insensitive full-string equality, mirroring TString::CompareTo(..., TString::kIgnoreCase) == 0.
| a | first string |
| b | second string |
Definition at line 212 of file PStringUtils.cpp.
Referenced by PMsrHandler::HandleFitParameterEntry(), PMsrHandler::HandleFourierEntry(), PMsrHandler::HandleGlobalEntry(), PMsrHandler::HandleRunEntry(), PMusrCanvas::IsScaleN0AndBkg(), and PRunSingleHisto::IsScaleN0AndBkg().
|
static |
Returns true if the string is a complete integer or floating point literal (optionally signed, with decimal point and/or exponent). Mirrors TString::IsFloat() for the relevant cases.
| str | string to be checked |
Returns true if the string is a complete integer or floating point literal (optionally signed, with decimal point and/or exponent). Mirrors the semantics of TString::IsFloat() for the relevant cases.
| str | string to be checked |
Definition at line 111 of file PStringUtils.cpp.
Referenced by PMsrHandler::HandleGlobalEntry(), and PMsrHandler::HandleRunEntry().
|
static |
Returns true if the string is a (possibly signed) integer literal, i.e. a non-empty sequence of decimal digits with an optional single leading sign (+/-). Slightly more permissive than TString::IsDigit(), which rejects a sign, so that e.g. "-5" is also recognised.
| str | string to be checked |
Returns true if the string is an integer literal, i.e. a non-empty sequence of decimal digits with an optional single leading sign (+/-). This is slightly more permissive than TString::IsDigit(), which rejects a sign, so that negative/positive integers such as "-5" or "+42" are also recognised.
| str | string to be checked |
Definition at line 77 of file PStringUtils.cpp.
Referenced by PMsrHandler::FillParameterInUse(), PMsrHandler::GetNoOfFitParameters(), PMsrHandler::HandleRunEntry(), PStartupHandler::OnCharacters(), and PMsrHandler::WriteMsrLogFile().
|
static |
Splits a string into tokens on any character contained in delimiters, skipping empty tokens. Mirrors TString::Tokenize().
| str | input string to be tokenized |
| delimiters | set of delimiter characters |
Splits a string into tokens on any character contained in delimiters, skipping empty tokens. Mirrors the semantics of TString::Tokenize().
| str | input string to be tokenized |
| delimiters | set of delimiter characters |
Definition at line 48 of file PStringUtils.cpp.
Referenced by PFitter::CheckCommands(), PMsrHandler::CheckFuncs(), PMsrHandler::CheckMaps(), PFitter::ExecuteFitRange(), PFitter::ExecuteFix(), PFitter::ExecutePrintLevel(), PFitter::ExecuteRelease(), PRunDataHandler::FileExistsCheck(), PRunDataHandler::FileExistsCheck(), PRunDataHandler::FileExistsCheck(), PRunDataHandler::FileNameFromTemplate(), PMsrHandler::FillParameterInUse(), PMsrHandler::GetNoOfFitParameters(), PFitter::GetParFromFun(), PFitter::GetPhaseParams(), PMsrHandler::HandleFitParameterEntry(), PMsrHandler::HandleFourierEntry(), PMsrHandler::HandleGlobalEntry(), PMsrHandler::HandlePlotEntry(), PMsrHandler::HandleRunEntry(), PMusrCanvas::IsScaleN0AndBkg(), PRunSingleHisto::IsScaleN0AndBkg(), PTheory::MakeCleanAndTidyPolynom(), PTheory::MakeCleanAndTidyTheoryBlock(), PTheory::MakeCleanAndTidyUserFcn(), msr2msr_param(), msr2msr_run(), msr2msr_theory(), musrFT_filter_histo(), PStartupHandler::OnCharacters(), PMsrHandler::ParseFourierPhaseParIterVector(), PMsrHandler::ParseFourierPhaseParVector(), PMsrHandler::ParseFourierPhaseValueVector(), PTheory::PTheory(), PRunDataHandler::ReadAsciiFile(), PRunDataHandler::ReadDatFile(), PRunDataHandler::ReadDBFile(), PRunDataHandler::ReadMduAsciiFile(), PRunDataHandler::ReadRootFile(), PRunDataHandler::ReadWkmFile(), PRunAsymmetry::SetFitRangeBin(), PRunAsymmetryBNMR::SetFitRangeBin(), PRunAsymmetryRRF::SetFitRangeBin(), PRunMuMinus::SetFitRangeBin(), PRunSingleHisto::SetFitRangeBin(), PRunSingleHistoRRF::SetFitRangeBin(), and PMsrHandler::WriteMsrLogFile().
|
static |
Converts the leading part of the string to a double. Mirrors TString::Atof(). Returns 0.0 if no conversion is possible.
If ok is non-null it is set to true when a value was parsed and to false on error (no number, or value out of range), allowing callers to distinguish a legitimate 0.0 from a failed conversion.
| str | string to be converted |
| ok | optional out-parameter signalling conversion success |
Converts the leading part of the string to a double, mirroring TString::Atof(). Returns 0.0 if no conversion is possible.
Like ToInt(), conversion errors can be reported through the optional ok out-parameter: it is set to true when a value was parsed and to false otherwise (no number present, or the value is out of range). This lets callers distinguish a legitimate 0.0 from a failed conversion. strtod() (rather than std::from_chars) is used so that the accepted input set stays identical to TString::Atof() (leading whitespace is skipped, a leading '+' is honoured, trailing characters are ignored). A null ok preserves the historic fire-and-forget behaviour.
| str | string to be converted |
| ok | optional out-parameter signalling conversion success |
Definition at line 189 of file PStringUtils.cpp.
Referenced by PMsrHandler::HandleFitParameterEntry(), PMsrHandler::HandleFourierEntry(), PMsrHandler::HandleGlobalEntry(), PMsrHandler::HandlePlotEntry(), PMsrHandler::HandleRunEntry(), and PMsrHandler::ParseFourierPhaseValueVector().
|
static |
Converts the leading part of the string to an int (base 10). Mirrors TString::Atoi(). Returns 0 if no conversion is possible.
If ok is non-null it is set to true when a valid integer was parsed and to false on error (no digits, or value out of int range). This allows callers to distinguish a legitimate 0 from a failed conversion, which the bare return value cannot express.
| str | string to be converted |
| ok | optional out-parameter signalling conversion success |
Converts the leading part of the string to an int (base 10), mirroring TString::Atoi(). Returns 0 if no conversion is possible.
Uses std::from_chars so that conversion errors can be reported through the optional ok out-parameter: it is set to true when a valid integer was parsed (leading whitespace is skipped) and to false otherwise (no digits present, or the value is out of int range). Trailing non-numeric characters are ignored, as with TString::Atoi(). A null ok preserves the historic fire-and-forget behaviour.
| str | string to be converted |
| ok | optional out-parameter signalling conversion success |
Definition at line 152 of file PStringUtils.cpp.
Referenced by PMsrHandler::FillParameterInUse(), PMsrHandler::GetNoOfFitParameters(), PMsrHandler::HandleFitParameterEntry(), PMsrHandler::HandleFourierEntry(), PMsrHandler::HandleGlobalEntry(), PMsrHandler::HandlePlotEntry(), PMsrHandler::HandleRunEntry(), PStartupHandler::OnCharacters(), PMsrHandler::ParseFourierPhaseParIterVector(), PMsrHandler::ParseFourierPhaseParVector(), and PMsrHandler::WriteMsrLogFile().