DUNE: Uniform Navigational Environment  2022.04.1
DUNE::Utils::String Class Reference

Static Public Member Functions

template<typename Iterator >
static std::string join (Iterator begin, Iterator end, const std::string &separator)
 
static std::string filterDuplicates (char element, const std::string &subject)
 
static std::string ltrim (const std::string &str)
 
static void rightTrimInPlace (char *str)
 
static std::string rtrim (const std::string &str)
 
static void resize (char *str, int size)
 
static std::string trim (const std::string &str)
 
static void split (const std::string &s, const std::string &sep, std::vector< std::string > &lst)
 
template<typename Type >
static void split (const std::string &s, const std::string &sep, std::vector< Type > &lst)
 
template<typename Type >
static void splitMulti (const std::string &s, const std::string &sep0, const std::string &sep1, std::vector< std::vector< Type > > &lst)
 
static void toLowerCase (std::string &str)
 
static void toUpperCase (std::string &str)
 
static std::string toHex (const std::string &str)
 
static std::string toHex (const std::vector< char > &str)
 
static std::string toHex (int nr)
 
static std::vector< uint8_t > hexToBytes (const std::string &hex)
 
static std::string fromHex (const std::string &str)
 
static void assign (std::vector< char > &dst, const char *src)
 
static std::string getRemaining (const std::string &prefix, const std::string &str)
 
template<typename Type >
static std::string str (Type t)
 
static std::string str (const char *fmt,...)
 
static std::string strVl (const char *fmt, std::va_list ap)
 
static int format (char *str, size_t size, const char *fmt,...)
 
static int formatVl (char *str, size_t size, const char *fmt, std::va_list ap)
 
static void replaceWhiteSpace (std::string &str, char rep)
 
static std::string replace (const std::string &str, char rep, const std::string &pat)
 
static std::string replaceAll (const std::string &inStr, const std::string &searchStr, const std::string &replaceStr)
 
static std::string escape (const std::string &input)
 
static std::string unescape (const std::string &input, bool unescape_all=true)
 
static bool startsWith (const std::string &str, const std::string &prefix)
 
static bool endsWith (const std::string &str, const std::string &suffix)
 

Member Function Documentation

◆ assign()

void DUNE::Utils::String::assign ( std::vector< char > &  dst,
const char *  src 
)
static

Referenced by splitMulti().

◆ endsWith()

bool DUNE::Utils::String::endsWith ( const std::string &  str,
const std::string &  suffix 
)
static

Test if string 'str' ends with a specified 'suffix'.

Parameters
[in]strstring.
[in]suffixsuffix.
Returns
true if 'str' ends with 'suffix', false otherwise.

Referenced by formatVl(), and DUNE::Parsers::Config::parseFile().

◆ escape()

std::string DUNE::Utils::String::escape ( const std::string &  input)
static

Referenced by formatVl(), and DUNE::IMC::toJSON().

◆ filterDuplicates()

std::string DUNE::Utils::String::filterDuplicates ( char  element,
const std::string &  subject 
)
static

Filter duplicates of a given character in a string.

Parameters
elementelement to filter.
subjectstring to search for duplicates.
Returns
filtered string.

Referenced by join(), and DUNE::FileSystem::Path::normalize().

◆ format()

static int DUNE::Utils::String::format ( char *  str,
size_t  size,
const char *  fmt,
  ... 
)
inlinestatic

◆ formatVl()

static int DUNE::Utils::String::formatVl ( char *  str,
size_t  size,
const char *  fmt,
std::va_list  ap 
)
inlinestatic

◆ fromHex()

std::string DUNE::Utils::String::fromHex ( const std::string &  str)
static

Referenced by splitMulti().

◆ getRemaining()

std::string DUNE::Utils::String::getRemaining ( const std::string &  prefix,
const std::string &  str 
)
static

References str().

Referenced by splitMulti().

◆ hexToBytes()

std::vector< uint8_t > DUNE::Utils::String::hexToBytes ( const std::string &  hex)
static

Referenced by splitMulti().

◆ join()

template<typename Iterator >
static std::string DUNE::Utils::String::join ( Iterator  begin,
Iterator  end,
const std::string &  separator 
)
inlinestatic

◆ ltrim()

std::string DUNE::Utils::String::ltrim ( const std::string &  str)
static

Strip whitespace from the beginning of a string.

Parameters
strobject string.
Returns
string without leading whitespaces.

Referenced by join(), and trim().

◆ replace()

std::string DUNE::Utils::String::replace ( const std::string &  str,
char  rep,
const std::string &  pat 
)
static

Referenced by formatVl(), and DUNE::IMC::toJSON().

◆ replaceAll()

std::string DUNE::Utils::String::replaceAll ( const std::string &  inStr,
const std::string &  searchStr,
const std::string &  replaceStr 
)
static

Replace all occurrences of a substring in a string.

Parameters
[in]inStrstring.
[in]searchStrsubstring to search for.
[in]replaceStrsubstring replacement.
Returns
resulting string with all substring occurrences replaced.

Referenced by formatVl().

◆ replaceWhiteSpace()

void DUNE::Utils::String::replaceWhiteSpace ( std::string &  str,
char  rep 
)
static

Referenced by formatVl().

◆ resize()

void DUNE::Utils::String::resize ( char *  str,
int  size 
)
static

Resize string by replacing any extra characters with '\0'.

If size is greater than current size, the string is untouched. If size is lower than 0, the resulting size is [strlen(str) + size].

Parameters
strobject string
sizenew size

Referenced by join(), and DUNE::Parsers::Config::parseFile().

◆ rightTrimInPlace()

void DUNE::Utils::String::rightTrimInPlace ( char *  str)
static

Strip whitespace from the end of a string in place.

Parameters
[in,out]strstring.

Referenced by join(), and DUNE::Parsers::Config::parseFile().

◆ rtrim()

std::string DUNE::Utils::String::rtrim ( const std::string &  str)
static

Strip whitespace from the end of a string.

Parameters
strobject string.
Returns
string without trailing whitespaces.

Referenced by join(), and trim().

◆ split() [1/2]

◆ split() [2/2]

template<typename Type >
static void DUNE::Utils::String::split ( const std::string &  s,
const std::string &  sep,
std::vector< Type > &  lst 
)
inlinestatic

Split a string into a vector of given type.

Parameters
sstring to split.
sepseparator string.
lstvector of Type.

References trim().

◆ splitMulti()

template<typename Type >
static void DUNE::Utils::String::splitMulti ( const std::string &  s,
const std::string &  sep0,
const std::string &  sep1,
std::vector< std::vector< Type > > &  lst 
)
inlinestatic

◆ startsWith()

bool DUNE::Utils::String::startsWith ( const std::string &  str,
const std::string &  prefix 
)
static

Test if string 'str' starts with a specified 'prefix'.

Parameters
[in]strstring.
[in]prefixprefix.
Returns
true if 'str' starts with 'prefix', false otherwise.

Referenced by formatVl().

◆ str() [1/2]

template<typename Type >
static std::string DUNE::Utils::String::str ( Type  t)
inlinestatic

Referenced by DUNE::Utils::OptionParser::add(), DUNE::Hardware::LUCL::BootLoader::BootLoader(), DUNE::Navigation::BasicNavigation::checkUncertainty(), DUNE::Power::Model::computeIMUEnergy(), DUNE::Control::BasicRemoteOperation::consume(), DUNE::Control::PathController::consume(), DUNE::Control::BasicAutopilot::consume(), DUNE::Compression::Bzip2Decompressor::decompressBlock(), DUNE::Compression::ZlibDecompressor::decompressBlock(), DUNE::Hardware::PWM::disable(), DUNE::Parsers::NMEAReader::eos(), DUNE::Hardware::LUCL::BootLoader::flash(), DUNE::Parsers::Config::get(), getRemaining(), DUNE::Hardware::GPIO::getValue(), DUNE::Hardware::GPIO::GPIO(), DUNE::Hardware::IntelHEX::IntelHEX(), join(), DUNE::Coordinates::latitudeToNMEA(), DUNE::Coordinates::longitudeToNMEA(), DUNE::Control::PathController::onEntityReservation(), DUNE::Control::BottomTracker::onEstimatedState(), DUNE::Parsers::operator<<(), DUNE::Parsers::Config::parseFile(), DUNE::Parsers::PlanConfigParser::parseZUnits(), DUNE::Hardware::PWM::PWM(), DUNE::Tasks::Parameter::read(), DUNE::Math::Matrix::readFromLines(), DUNE::Streams::sanitize(), DUNE::Tasks::Profiles::select(), DUNE::Tasks::MessageFilter::setupRates(), DUNE::Hardware::GPIO::setValue(), DUNE::Control::BasicAutopilot::signalBadVertical(), DUNE::Control::BasicAutopilot::signalBadYaw(), DUNE::Parsers::NMEASentence::str(), Transports::IridiumSBD::SessionResultCode::translate(), Sensors::AIS::ShipTypeCode::translate(), DUNE::Tasks::Profiles::unselect(), DUNE::Monitors::ServoPositionMonitor< T >::updateAndTest(), DUNE::Utils::OptionParser::usage(), and DUNE::Media::VideoCapture::VideoCapture().

◆ str() [2/2]

static std::string DUNE::Utils::String::str ( const char *  fmt,
  ... 
)
inlinestatic

References strVl().

◆ strVl()

static std::string DUNE::Utils::String::strVl ( const char *  fmt,
std::va_list  ap 
)
inlinestatic

References formatVl().

Referenced by DUNE::Parsers::NMEASentence::setField(), and str().

◆ toHex() [1/3]

std::string DUNE::Utils::String::toHex ( const std::string &  str)
static

References format().

Referenced by splitMulti(), and DUNE::IMC::toJSON().

◆ toHex() [2/3]

std::string DUNE::Utils::String::toHex ( const std::vector< char > &  str)
static

References format().

◆ toHex() [3/3]

std::string DUNE::Utils::String::toHex ( int  nr)
static

◆ toLowerCase()

void DUNE::Utils::String::toLowerCase ( std::string &  str)
static

◆ toUpperCase()

void DUNE::Utils::String::toUpperCase ( std::string &  str)
static

◆ trim()

std::string DUNE::Utils::String::trim ( const std::string &  str)
static

Strip whitespace from the beginning and end of a string.

Parameters
strobject string.
Returns
string without leading and trailing whitespaces.

References ltrim(), and rtrim().

Referenced by join(), DUNE::Utils::TupleList::operator<<(), DUNE::Parsers::NMEASentence::parse(), DUNE::Parsers::Config::parseFile(), DUNE::Hardware::BasicModem::readRaw(), and split().

◆ unescape()

std::string DUNE::Utils::String::unescape ( const std::string &  input,
bool  unescape_all = true 
)
static

Referenced by formatVl().

Collaboration diagram for DUNE::Utils::String:
Collaboration graph