VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
VoltMod::Strings Class Reference

Collection of static string manipulation utilities. More...

#include <Strings.hpp>

Static Public Member Functions

static std::string ToLower (std::string_view str)
 
static std::string Trim (std::string_view str)
 
static std::string Join (const std::vector< std::string > &parts, std::string_view delimiter)
 
static std::string JoinNonEmpty (const std::vector< std::string > &parts, std::string_view delimiter)
 
static bool StartsWith (std::string_view str, std::string_view prefix)
 
static bool ContainsIgnoreCase (std::string_view str, std::string_view substr)
 
static std::string SubstituteTokens (std::string text, const Tokens &tokens)
 
static std::string EscapeHtml (std::string_view text)
 
static std::string QuoteConsoleArg (std::string_view value)
 
static std::string TruncateUtf8 (std::string_view text, std::size_t maxBytes, std::string_view ellipsis="...")
 
static bool IsNumeric (std::string_view str)
 
static void CopyToBuffer (char *buffer, std::size_t size, std::string_view text) noexcept
 
static std::string DisplayNameOr (int64_t id, std::string_view name, std::size_t maxBytes=20)
 

Detailed Description

Collection of static string manipulation utilities.

Definition at line 34 of file Strings.hpp.

Member Function Documentation

◆ ContainsIgnoreCase()

bool VoltMod::Strings::ContainsIgnoreCase ( std::string_view  str,
std::string_view  substr 
)
static

Definition at line 153 of file Strings.cpp.

References VoltMod::ReadFile(), and ToLower().

◆ CopyToBuffer()

void VoltMod::Strings::CopyToBuffer ( char *  buffer,
std::size_t  size,
std::string_view  text 
)
staticnoexcept

Copy text into a caller's C error buffer of size bytes, cut to fit and NUL-terminated.

Definition at line 257 of file Strings.cpp.

References VoltMod::ReadFile().

Referenced by VoltMod::Internal::PluginModule::Attach(), and VoltMod_HostStart().

◆ DisplayNameOr()

std::string VoltMod::Strings::DisplayNameOr ( int64_t  id,
std::string_view  name,
std::size_t  maxBytes = 20 
)
static

Row display text, HTML-escaped: the (UTF-8-safely truncated) name, or id when unnamed.

Definition at line 269 of file Strings.cpp.

References EscapeHtml(), VoltMod::ReadFile(), and TruncateUtf8().

◆ EscapeHtml()

std::string VoltMod::Strings::EscapeHtml ( std::string_view  text)
static

Escape ‘& < > " ’` as HTML entities for safe embedding in center-HTML panels.

Definition at line 185 of file Strings.cpp.

References VoltMod::ReadFile().

Referenced by DisplayNameOr(), VoltMod::RenderCaptureOverlay(), VoltMod::RenderHeader(), VoltMod::RenderMenuHtml(), and VoltMod::RowText().

◆ IsNumeric()

bool VoltMod::Strings::IsNumeric ( std::string_view  str)
static

◆ Join()

std::string VoltMod::Strings::Join ( const std::vector< std::string > &  parts,
std::string_view  delimiter 
)
static

◆ JoinNonEmpty()

std::string VoltMod::Strings::JoinNonEmpty ( const std::vector< std::string > &  parts,
std::string_view  delimiter 
)
static

Join parts with delimiter, skipping empty ones.

For text assembled from optional pieces - a ban notice's reason, expiry and appeal link, say. Skipping is the point: a piece that is not configured must not leave a dangling delimiter or a bare label behind it.

Definition at line 130 of file Strings.cpp.

References VoltMod::ReadFile().

◆ QuoteConsoleArg()

std::string VoltMod::Strings::QuoteConsoleArg ( std::string_view  value)
static

Quote value as a single console-command argument: wrapped in "</tt>, with <tt>" and \ escaped.

The engine's command parser splits on whitespace and treats ; as a command separator, so an unquoted value containing either is truncated or runs a second command. A newline cannot be escaped by quoting at all - it always ends the line - which is why ConVars::ExecuteServerCommand rejects one outright rather than relying on this.

Definition at line 216 of file Strings.cpp.

References VoltMod::ReadFile().

Referenced by VoltMod::ConVars::SetByConsole().

◆ StartsWith()

bool VoltMod::Strings::StartsWith ( std::string_view  str,
std::string_view  prefix 
)
static

Definition at line 148 of file Strings.cpp.

References VoltMod::ReadFile().

Referenced by VoltMod::FilterPlayers(), and VoltMod::ParseTargetToken().

◆ SubstituteTokens()

std::string VoltMod::Strings::SubstituteTokens ( std::string  text,
const Tokens &  tokens 
)
static

Replace each {key} occurrence in text with its mapped value.

Definition at line 176 of file Strings.cpp.

References VoltMod::ReadFile(), and VoltMod::ReplaceAll().

Referenced by VoltMod::Translations::Get(), and VoltMod::Json::SubstituteTokens().

◆ ToLower()

◆ Trim()

std::string VoltMod::Strings::Trim ( std::string_view  str)
static

◆ TruncateUtf8()

std::string VoltMod::Strings::TruncateUtf8 ( std::string_view  text,
std::size_t  maxBytes,
std::string_view  ellipsis = "..." 
)
static

Truncate to at most maxBytes bytes plus ellipsis, cutting at a UTF-8 sequence boundary so multibyte text (e.g. Cyrillic) never renders a split character.

Definition at line 233 of file Strings.cpp.

References VoltMod::ReadFile().

Referenced by DisplayNameOr().


The documentation for this class was generated from the following files: