string
Text operations plus Python's string constants, exposed as free functions so a .purr program writes string.upper("x").
import string
print(string.upper("purr")) # PURR
print(string.split("a,b,c", ",")) # ['a', 'b', 'c']
print(string.join("-", ["a", "b"])) # a-bWhat's here
Constants —
ascii_lowercase,ascii_uppercase,ascii_letters,digits,hexdigits,octdigits,punctuation,whitespace.Case —
upper,lower,capitalize,title,swapcase.Trimming —
strip,lstrip,rstrip.Search / test —
startswith,endswith,contains,find,rfind,count.Transform —
replace,split,splitlines,capwords,join.Padding —
ljust,rjust,center,zfill.Classification —
isdigit,isalpha,isalnum,isspace,isupper,islower.
Functions returning std::string / std::vector<std::string> allocate their result on the heap; the predicate/index functions (bool/long) do not.
Per-function docs (parameters, runtime complexity, heap behavior) are in string.hpp. Tested in ../tests/string_test.cpp; ASan + Valgrind clean via the QA gate (security/run-valgrind.sh).
Functions
Uppercase.
Returns a new string with every ASCII lowercase letter mapped to uppercase via std::toupper; non-letters and bytes ≥ 0x80 are copied unchanged (ASCII-only).
s | input. |
s uppercased.
O(n).
allocates the result.
CheatahString.CaseStringCompileRun.UpperStdlibE2E.String SystemApps.EventLog SystemApps.Integrity …Lowercase.
Returns a new string with every ASCII uppercase letter mapped to lowercase via std::tolower; non-letters and bytes ≥ 0x80 are copied unchanged (ASCII-only).
s | input. |
s lowercased.
O(n).
allocates the result.
CheatahString.CaseStringCompileRun.LowerStdlibE2E.StringCapitalize: first char upper, rest lower.
Uppercases the first character and lowercases all remaining characters (ASCII-only); an empty input is returned unchanged.
s | input. |
capitalized s.
O(n).
allocates.
CheatahString.CaseStringCompileRun.CapitalizeStdlibE2E.StringTitle-case each word.
Uppercases the first letter of every run of letters and lowercases the rest; any non-letter (digits, punctuation, whitespace) acts as a word boundary (ASCII-only).
s | input. |
title-cased s.
O(n).
allocates.
CheatahString.CaseStringCompileRun.TitleStdlibE2E.StringSwap the case of each letter.
Returns a new string with each ASCII letter's case inverted; non-letters are left unchanged (ASCII-only).
s | input. |
case-swapped s.
O(n).
allocates.
CheatahString.CaseStringCompileRun.SwapcaseStdlibE2E.StringStrip leading chars.
Removes characters from the front only, as long as each is in the chars set (a bag of characters, not a substring); defaults to ASCII whitespace.
s | input. |
chars | cut set. |
left-trimmed s.
O(n·m) (m = size of the chars set; a constant for the default).
allocates.
CheatahString.TrimmingStringCompileRun.LstripStdlibE2E.StringStrip trailing chars.
Removes characters from the end only, as long as each is in the chars set (a bag of characters, not a substring); defaults to ASCII whitespace.
s | input. |
chars | cut set. |
right-trimmed s.
O(n·m) (m = size of the chars set; a constant for the default).
allocates.
CheatahString.TrimmingStringCompileRun.RstripStdlibE2E.StringStrip leading+trailing chars.
Removes characters from both ends as long as each is present in the chars set (the set is a bag of characters, not a substring); defaults to ASCII whitespace. An empty chars set strips nothing.
s | input. |
chars | cut set. |
trimmed s.
O(n·m) (m = size of the chars set; a constant for the default).
allocates the result plus lstrip's intermediate string.
CheatahString.TrimmingStringCompileRun.StripStdlibE2E.StringPrefix test.
Case-sensitive, byte-exact comparison; an empty prefix always matches.
s | input. |
prefix | sought prefix. |
true iff s starts with prefix.
O(n).
none.
CheatahString.SearchAndTestStringCompileRun.StartswithStdlibE2E.StringSuffix test.
Case-sensitive, byte-exact comparison; an empty suffix always matches.
s | input. |
suffix | sought suffix. |
true iff s ends with suffix.
O(n).
none.
CheatahString.SearchAndTestStringCompileRun.EndswithStdlibE2E.Stringcontains · 2 overloads
Substring test.
Case-sensitive search for sub anywhere in s; an empty sub is always considered present.
s | input. |
sub | needle. |
true iff sub occurs in s.
O(n·m).
none.
CheatahString.SearchAndTestStringCompileRun.ContainsStdlibE2E.Stringfind · 2 overloads
First index of sub.
Returns the 0-based byte index of the first (leftmost) case-sensitive match, or -1 if not found; an empty sub returns 0.
s | input. |
sub | needle. |
index, or -1.
O(n·m).
none.
CheatahString.SearchAndTestStringCompileRun.FindStdlibE2E.StringLast index of sub.
Returns the 0-based byte index of the last (rightmost) case-sensitive match, or -1 if not found; an empty sub returns the length of s.
s | input. |
sub | needle. |
index, or -1.
O(n·m).
none.
CheatahString.SearchAndTestStringCompileRun.RfindStdlibE2E.StringCount non-overlapping sub.
Counts left-to-right, non-overlapping case-sensitive matches; matching Python, an empty sub returns len(s) + 1.
s | input. |
sub | needle. |
occurrence count.
O(n·m).
none.
CheatahString.SearchAndTestStringCompileRun.CountStdlibE2E.String SystemApps.EventLogReplace all from with to.
Replaces every non-overlapping, case-sensitive occurrence of from with to; an empty from leaves s unchanged (unlike Python).
s | input. |
from, to | needle/replacement. |
new string.
O(n·m + result length).
allocates.
CheatahString.TransformStringCompileRun.ReplaceStdlibE2E.Stringsplit · 2 overloads
Split on sep.
Splits at each non-overlapping occurrence of sep, keeping empty fields (e.g. "a,,b" yields three parts, leading/trailing separators yield empty strings); the result always has at least one element.
s | input. |
sep | separator (empty → the whole string as one part). |
the parts.
O(n·m).
allocates a vector of strings.
StringCompileRun.SplitStdlibE2E.StringSplit into lines.
Breaks on \n, \r, and \r\n (treated as a single break) with the line terminators removed; a trailing newline does not produce a final empty line, and an empty input yields an empty vector.
s | input. |
the lines (newlines removed).
O(n).
allocates a vector of strings.
CheatahString.TransformStringCompileRun.SplitlinesStdlibE2E.String SystemApps.EventLogPython string.capwords: split on whitespace, capitalize, re-join with spaces.
Capitalizes each whitespace-delimited word (first letter upper, rest lower) and re-joins with single spaces, so all runs of original whitespace collapse and leading/trailing whitespace is dropped.
s | input. |
the result.
O(n).
allocates a vector of words plus the result.
CheatahString.TransformStringCompileRun.CapwordsStdlibE2E.StringLeft-justify to width.
Pads s on the right with the fill character up to width; if s is already at least width long it is returned unchanged. Only the first character of fill is used (an empty fill defaults to a space).
s | input. |
width | target. |
fill | pad char. |
padded s (or s if already ≥ width).
O(n + width).
allocates.
CheatahString.PaddingStringCompileRun.LjustStdlibE2E.String SystemApps.GradeReportRight-justify to width.
Pads s on the left with the fill character up to width; if s is already at least width long it is returned unchanged. Only the first character of fill is used (an empty fill defaults to a space).
s | input. |
width | target. |
fill | pad char. |
padded s.
O(n + width).
allocates the result plus concatenation temporaries.
CheatahString.PaddingStringCompileRun.RjustStdlibE2E.String SystemApps.GradeReportCenter within width.
Pads both sides with the fill character; when the padding is odd the extra character goes on the right. Returns s unchanged if it is already at least width long, and only the first character of fill is used (empty → space).
s | input. |
width | target. |
fill | pad char. |
padded s.
O(n + width).
allocates the result plus concatenation temporaries.
CheatahString.PaddingStringCompileRun.CenterStdlibE2E.String SystemApps.GradeReportZero-fill on the left to width.
Left-pads with '0' to width; if s begins with a '+' or '-' sign the zeros are inserted after the sign. Returns s unchanged if already at least width long.
s | input. |
width | target. |
'0'-padded s.
O(n + width).
allocates the result plus concatenation temporaries.
CheatahString.PaddingStringCompileRun.ZfillStdlibE2E.StringAll digits?
True only if s is non-empty and every character is an ASCII decimal digit; the empty string returns false (matching Python).
s | input. |
true iff non-empty and all 0–9.
O(n).
none.
CheatahString.ClassificationStringCompileRun.IsdigitStdlibE2E.StringAll letters?
True only if s is non-empty and every character is an ASCII letter (std::isalpha); the empty string returns false.
s | input. |
true iff non-empty and all alphabetic.
O(n).
none.
CheatahString.ClassificationStringCompileRun.IsalphaStdlibE2E.StringAll alphanumeric?
True only if s is non-empty and every character is an ASCII letter or digit (std::isalnum); the empty string returns false.
s | input. |
true iff non-empty and all letters/digits.
O(n).
none.
StringCompileRun.IsalnumStdlibE2E.StringAll whitespace?
True only if s is non-empty and every character is ASCII whitespace (std::isspace: space, tab, newline, CR, form-feed, vertical tab); the empty string returns false.
s | input. |
true iff non-empty and all whitespace.
O(n).
none.
StringCompileRun.IsspaceStdlibE2E.StringAll uppercase?
True iff s contains at least one ASCII uppercase letter and no lowercase letters; non-letter characters are ignored, so e.g. "ABC123" is uppercase but "123" and the empty string are not.
s | input. |
true iff s has ≥ 1 uppercase letter and no lowercase.
O(n).
none.
CheatahString.ClassificationStringCompileRun.IsupperStdlibE2E.StringAll lowercase?
True iff s contains at least one ASCII lowercase letter and no uppercase letters; non-letter characters are ignored, so e.g. "abc123" is lowercase but "123" and the empty string are not.
s | input. |
true iff s has ≥ 1 lowercase letter and no uppercase.
O(n).
none.
CheatahString.ClassificationStringCompileRun.IslowerStdlibE2E.StringJoin parts with sep.
Concatenates each element of parts with sep inserted only between elements (no leading or trailing separator); an empty range yields an empty string.
sep | separator. |
parts | any range of string-like values. |
the joined string.
O(total length).
allocates the result.
CheatahString.TransformStringCompileRun.JoinStdlibE2E.StringConstants & variables
a–z.
A–Z.
a–zA–Z.
0–9.
hex digits.
octal digits.
ASCII punctuation.
ASCII whitespace.
