StringUtils
in package
String manipulation utilities.
Provides static methods for encoding strings, creating CSS class names, and handling translation separators.
Tags
Table of Contents
Properties
- $firstSeparator : string|null
- Cached first separator character.
- $separators : string|null
- Cached separators value (preg_quote'd).
Methods
- encodeURI() : string
- Encode a URI string matching JavaScript's encodeURI behavior.
- getFilePath() : string
- Get the path of a file using the theme directory.
- getFirstSeparator() : string
- Get the first translation separator character.
- getSeparators() : string
- Get the translation separators pattern for regex use.
- makeCounterWithTotal() : string
- Create a counter string with total (e.g., "01/10").
- parseInlineMarkdown() : string
- Parse inline Markdown to HTML.
- printFilePath() : void
- Echo the path of a file using the theme directory.
- removeSoftHyphens() : string
- Remove soft hyphens from a string.
- removeSpaces() : string
- Remove all spaces from a string.
- replaceFirst() : string
- Replace the first occurrence of $needle in $haystack with $replace.
- resetSeparatorCache() : void
- Reset cached separator values.
- toClassName() : string
- Derive an opaque identity token for a term's lowercase text.
- toHex() : string
- Convert a string to hexadecimal representation.
Properties
$firstSeparator
Cached first separator character.
private
static string|null
$firstSeparator
= null
$separators
Cached separators value (preg_quote'd).
private
static string|null
$separators
= null
Methods
encodeURI()
Encode a URI string matching JavaScript's encodeURI behavior.
public
static encodeURI(string $url) : string
Parameters
- $url : string
-
URL to encode
Return values
string —Encoded URL
getFilePath()
Get the path of a file using the theme directory.
public
static getFilePath(string $filename) : string
Maps legacy paths to new asset locations:
- css/* -> dist/css/*
- icn/* -> assets/icons/*
- img/* -> assets/images/*
- js/* -> dist/js/*
Parameters
- $filename : string
-
Filename
Return values
string —File path if it exists, otherwise the filename
getFirstSeparator()
Get the first translation separator character.
public
static getFirstSeparator() : string
Return values
string —First separator character
getSeparators()
Get the translation separators pattern for regex use.
public
static getSeparators() : string
Returns the separator characters from settings, escaped for use in preg_split and similar functions.
Return values
string —Preg-quoted separator characters
makeCounterWithTotal()
Create a counter string with total (e.g., "01/10").
public
static makeCounterWithTotal(int $max, int $num) : string
Parameters
- $max : int
-
Total count
- $num : int
-
Current number
Return values
string —Formatted counter string
parseInlineMarkdown()
Parse inline Markdown to HTML.
public
static parseInlineMarkdown(string $text) : string
Supports: bold, italic, links, ~~strikethrough~~
Security:
Parameters
- $text : string
-
Input text with Markdown
Return values
string —HTML string
printFilePath()
Echo the path of a file using the theme directory.
public
static printFilePath(string $filename) : void
Parameters
- $filename : string
-
Filename
removeSoftHyphens()
Remove soft hyphens from a string.
public
static removeSoftHyphens(string $str) : string
Parameters
- $str : string
-
Input string
Return values
string —String without soft hyphens
removeSpaces()
Remove all spaces from a string.
public
static removeSpaces(string $s, string|bool|int $remove) : string
Parameters
- $s : string
-
Input string
- $remove : string|bool|int
-
Do not do anything if empty, false, or 0
Return values
string —String without spaces if requested
replaceFirst()
Replace the first occurrence of $needle in $haystack with $replace.
public
static replaceFirst(string $needle, string $replace, string $haystack) : string
Parameters
- $needle : string
-
Text to replace
- $replace : string
-
Replacement text
- $haystack : string
-
Input string
Return values
string —String with first occurrence replaced
resetSeparatorCache()
Reset cached separator values.
public
static resetSeparatorCache() : void
Call this if settings change during runtime.
toClassName()
Derive an opaque identity token for a term's lowercase text.
public
static toClassName(string $string) : string
Used in the reading view as the data_hex attribute so every occurrence of
the same term can be restyled in one pass when its status changes. The token
is computed per render and never stored or reversed back to text, so a short
one-way hash is sufficient. A pure [0-9a-f] hash is also selector-safe — no
CSS.escape needed — and is recomputed identically on both the PHP and JS
sides, so the API hex field keeps its exact role.
Parameters
- $string : string
-
String to derive the token from (typically WoTextLC)
Return values
string —16-character (64-bit) lowercase hex token
toHex()
Convert a string to hexadecimal representation.
public
static toHex(string $string) : string
Parameters
- $string : string
-
String to convert
Return values
string —Uppercase hexadecimal string