Porytiles
Loading...
Searching...
No Matches
string_utils.hpp File Reference

Utility functions for string manipulation and formatting. More...

#include <algorithm>
#include <cctype>
#include <format>
#include <ranges>
#include <regex>
#include <string>
#include "porytiles/utilities/dynamic_cased_name.hpp"
#include "porytiles/utilities/panic/panic.hpp"
Include dependency graph for string_utils.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  porytiles
 

Functions

bool porytiles::check_full_string_match (const std::string &str, const std::string &pattern)
 Checks if a string fully matches a regular expression pattern.
 
std::string porytiles::trim_prefix (const std::string &str, const std::string &prefix)
 Removes a prefix from a string if present.
 
void porytiles::trim (std::string &string)
 Removes leading and trailing whitespace from a string in-place.
 
std::vector< std::string > porytiles::split (std::string input, const std::string &delimiter)
 Splits a string into tokens based on a delimiter.
 
std::string & porytiles::trim_line_ending (std::string &line)
 Removes line ending characters from a string in-place.
 
std::string porytiles::trim_line_ending (const std::string &line)
 Removes line ending characters from a string.
 
template<typename T >
std::string porytiles::int_to_hex_str (T t)
 Converts an integer value to a hexadecimal string with "0x" prefix.
 
template<typename T >
std::string porytiles::pad_two_digits (T t)
 Converts an integer value to a minimum two-digit wide string representation.
 
std::string porytiles::to_string (const std::string &str)
 Identity function for to_string with std::string input.
 
std::string porytiles::to_string (bool value)
 Converts a boolean to its string representation.
 
template<typename T >
std::string porytiles::to_string (const std::vector< T > &vec)
 Converts a vector to a string representation with curly brace delimiters.
 
std::string porytiles::to_pascal_case (const std::string &s)
 Converts a string to PascalCase format.
 
std::string porytiles::to_snake_case (const std::string &s)
 Converts a string to snake_case format.
 
std::string porytiles::to_lower_str (const std::string &input)
 Converts all characters in a string to lowercase.
 
std::string porytiles::pal_filename (std::size_t pal_index)
 Constructs a palette filename from a palette index.
 
std::string porytiles::extract_tileset_shorthand (const std::string &tileset_name)
 Extracts the Pascal-case tileset short name from the full name.
 
DynamicCasedName porytiles::extract_tileset_cased_name (const std::string &tileset_name)
 Extracts the tileset short name and wraps it in a DynamicCasedName.
 

Detailed Description

Utility functions for string manipulation and formatting.

This header provides a collection of common string operations used throughout the Porytiles codebase, including:

  • Whitespace trimming and line ending normalization
  • String splitting and tokenization
  • Case conversion (PascalCase, snake_case, lowercase)
  • Numeric formatting (hexadecimal, zero-padded digits)
  • Regular expression matching utilities

All functions are inline to avoid ODR violations when included in multiple translation units.

Definition in file string_utils.hpp.