ASAPCabinetFE
 
Loading...
Searching...
No Matches
StringUtils Class Reference

Utility class for VPS-related string and data processing in ASAPCabinetFE. More...

#include <string_utils.h>

+ Collaboration diagram for StringUtils:

Public Member Functions

std::string normalizeString (const std::string &input) const
 Normalizes a string for strict comparison.
 
std::string normalizeStringLessAggressive (const std::string &input) const
 Normalizes a string with less aggressive rules.
 
std::string normalizeVersion (const std::string &version) const
 Normalizes a version string for comparison.
 
bool isVersionGreaterThan (const std::string &v1, const std::string &v2) const
 Compares two version strings.
 
std::string extractYearFromDate (const std::string &dateString) const
 Extracts the year from a date string.
 
std::string join (const nlohmann::json &array, const std::string &delimiter) const
 Joins a JSON array of strings into a single string.
 
std::string safeGetString (const nlohmann::json &j, const std::string &key, const std::string &defaultValue) const
 Safely extracts a string value from a JSON object.
 
std::string cleanString (const std::string &input) const
 
size_t levenshteinDistance (const std::string &s1, const std::string &s2) const
 
std::string toLower (const std::string &str) const
 
std::string extractCleanTitle (const std::string &input) const
 

Static Public Member Functions

static std::string safeGetMetadataString (const nlohmann::json &j, const std::string &key, const std::string &defaultValue="")
 Cleans a string by trimming whitespace and collapsing multiple spaces.
 
static std::string cleanMetadataString (const std::string &input)
 
static std::string capitalizeWords (const std::string &input)
 

Detailed Description

Utility class for VPS-related string and data processing in ASAPCabinetFE.

This class provides static methods to normalize strings, compare versions, extract years from dates, and join JSON arrays into strings. These utilities are used for processing VPS metadata, ensuring consistency in matching and matchmaking tasks. The methods are stateless (const) and can be extended via configUI for user-defined normalization or formatting rules.

Member Function Documentation

◆ extractYearFromDate()

std::string StringUtils::extractYearFromDate ( const std::string &  dateString) const

Extracts the year from a date string.

Parses the date string to extract a four-digit year, supporting formats like "DD.MM.YYYY" (e.g., "01.01.2023") or standalone "YYYY" (e.g., "2023"). Returns an empty string if no year is found.

Parameters
dateStringThe date string to parse.
Returns
The extracted year as a string, or empty if not found.
+ Here is the caller graph for this function:

◆ isVersionGreaterThan()

bool StringUtils::isVersionGreaterThan ( const std::string &  v1,
const std::string &  v2 
) const

Compares two version strings.

Normalizes the version strings using normalizeVersion, then compares them numerically if possible (e.g., "1.2" > "1.1"). Falls back to lexicographical comparison if numeric conversion fails. Returns true if v1 is greater than v2.

Parameters
v1The first version string to compare.
v2The second version string to compare.
Returns
True if v1 is greater than v2, false otherwise.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ join()

std::string StringUtils::join ( const nlohmann::json &  array,
const std::string &  delimiter 
) const

Joins a JSON array of strings into a single string.

Concatenates all string elements in the JSON array using the specified delimiter, skipping non-string elements with a debug log. Returns an empty string if the array is empty or contains no valid strings.

Parameters
arrayThe JSON array containing strings to join.
delimiterThe string to use as a separator between elements.
Returns
The joined string, or empty if no valid elements.
+ Here is the caller graph for this function:

◆ normalizeString()

std::string StringUtils::normalizeString ( const std::string &  input) const

Normalizes a string for strict comparison.

Converts the input string to lowercase and removes all non-alphanumeric characters, producing a simplified string for strict matching (e.g., in metadata comparison). This method can be customized via configUI for different normalization rules.

Parameters
inputThe input string to normalize.
Returns
The normalized string (lowercase, alphanumeric only).
+ Here is the caller graph for this function:

◆ normalizeStringLessAggressive()

std::string StringUtils::normalizeStringLessAggressive ( const std::string &  input) const

Normalizes a string with less aggressive rules.

Converts the input string to lowercase, removes specific punctuation (e.g., underscores, dashes), preserves spaces and parentheses, collapses multiple spaces into one, and trims whitespace. This method is suitable for less strict matching while retaining some structure.

Parameters
inputThe input string to normalize.
Returns
The normalized string (lowercase, with preserved spaces/parentheses).
+ Here is the caller graph for this function:

◆ normalizeVersion()

std::string StringUtils::normalizeVersion ( const std::string &  version) const

Normalizes a version string for comparison.

Trims whitespace, replaces commas with dots, and extracts the first part before a dash if it matches a numeric pattern (e.g., "1.2-beta" becomes "1.2"). This method ensures consistent version formatting for comparison.

Parameters
versionThe version string to normalize.
Returns
The normalized version string (trimmed, numeric format).
+ Here is the caller graph for this function:

◆ safeGetMetadataString()

std::string StringUtils::safeGetMetadataString ( const nlohmann::json &  j,
const std::string &  key,
const std::string &  defaultValue = "" 
)
static

Cleans a string by trimming whitespace and collapsing multiple spaces.

Removes leading and trailing whitespace characters from the input string and replaces any sequence of multiple internal spaces with a single space.

Parameters
inputThe string to clean.
Returns
The cleaned string.
+ Here is the caller graph for this function:

◆ safeGetString()

std::string StringUtils::safeGetString ( const nlohmann::json &  j,
const std::string &  key,
const std::string &  defaultValue 
) const

Safely extracts a string value from a JSON object.

Retrieves the string value associated with the given key from a JSON object. If the key is not found or the value is not a string, it returns a default value. Handles null values by returning the default.

Parameters
jThe JSON object to extract from.
keyThe key of the string value to extract.
defaultValueThe default string value to return if extraction fails.
Returns
The extracted string value or the default value.
+ Here is the caller graph for this function:

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