package stringx
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
On This Page
A collection of string utilities missing from OCaml's standard library
Install
dune-project
Dependency
Authors
Maintainers
Sources
v0.3.0.tar.gz
md5=547f83e21f1b53f003213bead916089e
sha512=f07f83ccae0b83a9a43fc75d48a83f0f404a738a52408df2bac34213493bbf3b82f4affbaa2d1de451d5274023bc2d3aad8dba44e2f350ccedb5007b68dedc9c
doc/CHANGELOG.html
Changelog
[Unreleased]
[v0.3.0] - 2025-07-01
- add:
mapReturns a copy of the string with all Unicode code points mapped by the given function. The mapping function must return a valid Unicode code point (Uchar.t) for every input; no code points are dropped. Unicode-aware: decodes the string into code points, applies the function, then re-encodes into UTF-8. - add:
filter_mapReturns a new string by applying the given function to each Unicode code point in the input string. If the function returns [Some u'], [u'] is included in the result; if [None], the code point is dropped. Unicode-aware: decodes the string into code points, applies the function, then re-encodes into UTF-8. - add:
iterApplies the given function to each Unicode code point in the string, in sequence, for side effects only. Unicode-aware: decodes the string into code points and applies the function to each. - add:
foldApplies the given function to each Unicode code point in the string, carrying along an accumulator, and returns the final accumulator value. Unicode-aware: decodes the string into code points and applies the function to each. - add:
expand_tabsExpands tab characters ('\t') in the string to spaces, depending on the current column and tab size. The column is reset to zero after each newline ('\n'). CJK characters are treated as width 2. Raises [Invalid_argument] if [tab_size] <= 0. - add:
first_rune_to_lowerConverts the first Unicode code point to lower case if it is an uppercase ASCII letter. Unicode-aware: only the first code point is affected, the rest are unchanged. - add:
first_rune_to_upperConverts the first Unicode code point to upper case if it is a lowercase ASCII letter. Unicode-aware: only the first code point is affected, the rest are unchanged. - add:
insertInserts [src] into [dst] at the given Unicode code point index. Index is counted by code points (runes), not bytes. Raises [Invalid_argument] if [index] is out of range (index < 0 or index > length of [dst]). - add:
last_partitionSplits a string by the last instance of a separator into three parts: ([head], [match], [tail]). If the separator is found, returns the part before, the separator itself, and the part after. If not found, returns ("", "", [str]). Operates on bytes, not code points. - add:
left_justifyLeft-justifies a string in a field of the given width, padding with the given pad string on the right if needed. If the string is longer than the width or pad is empty, the original string is returned. Unicode-aware: counts code points, not bytes. - add:
partitionSplits a string by the first instance of a separator into three parts: ([head], [match], [tail]). If the separator is found, returns the part before, the separator itself, and the part after. If not found, returns ([str], "", ""). Operates on bytes, not code points. - add:
right_justifyRight-justifies a string in a field of the given width, padding with the given pad string on the left if needed. If the string is longer than the width or pad is empty, the original string is returned. Unicode-aware: counts code points, not bytes. - add:
rune_widthReturns the character width of a Unicode code point in a monotype font. Multi-byte (East Asian wide) characters are usually twice the width of single byte characters. Algorithm based on PHP's mb_strwidth. - add:
scrubReplaces invalid UTF-8 byte sequences in a string with a replacement string. Adjacent invalid bytes are replaced only once. Unicode-aware. - add:
shuffleRandomizes the order of Unicode code points in a string. Uses OCaml's Random module as the random source. Unicode-aware: shuffles by code points, not bytes. Equivalent to PHP's str_shuffle. - add:
shuffle_sourceRandomizes the order of Unicode code points in a string using the given random state ([Random.State.t]). Unicode-aware: shuffles by code points, not bytes. Equivalent to PHP's str_shuffle with custom random source. - add:
sliceSlices a string by Unicode code points (runes). Returns the substring from [start] (inclusive) to [end_] (exclusive). Negative [end_] means slice to the end of string. Equivalent to PHP's mb_substr. Raises [Invalid_argument] if indices are out of range. - add:
squeezeDeletes adjacent repeated Unicode code points in a string. If a pattern is given, only code points matching the pattern are squeezed. Unicode-aware. Equivalent to Ruby's String#squeeze.
[v0.2.0] - 2025-06-29
- add:
trimRemoves all leading and trailing Unicode code points in the given cutset from the string. Unicode-aware. - add:
trim_funcRemoves all leading and trailing Unicode code points from the string that satisfy the given predicate function. Unicode-aware. - add:
trim_leftRemoves all leading Unicode code points in the given cutset from the string. Unicode-aware. - add:
trim_left_funcRemoves all leading Unicode code points from the string that satisfy the given predicate function. Unicode-aware. - add:
trim_rightRemoves all trailing Unicode code points in the given cutset from the string. Unicode-aware. - add:
trim_right_funcRemoves all trailing Unicode code points from the string that satisfy the given predicate function. Unicode-aware. - add:
trim_spaceRemoves all leading and trailing Unicode whitespace from the string. Unicode-aware. - add:
trim_suffixRemoves the provided trailing suffix, if present. Operates on bytes, not code points. - add:
to_lowerConverts all ASCII letters in the string to lowercase. (Full Unicode lowercasing not yet supported.) - add:
to_titleConverts all ASCII letters in the string to uppercase (title case). (Full Unicode title case not yet supported.) - add:
to_upperConverts all ASCII letters in the string to uppercase. (Full Unicode uppercasing not yet supported.) - add:
to_camel_caseConverts words separated by space, underscore, or hyphen to camelCase. The first word is lowercased, subsequent words are capitalized. Handles all-uppercase words and preserves leading/trailing separators. - add:
to_kebab_caseConverts a string to kebab-case. Uppercase ASCII letters are converted to lowercase. Word boundaries are detected at transitions and replaced with a single hyphen. Multiple separators are normalized, and leading/trailing hyphens are removed. - add:
to_pascal_caseConverts words separated by space, underscore, or hyphen to PascalCase. Each word is capitalized. Handles all-uppercase words and removes leading/trailing separators. - add:
to_snake_caseConverts a string to snake_case. Uppercase ASCII letters are converted to lowercase. Word boundaries are detected and replaced with a single underscore. Multiple separators are normalized, and leading/trailing underscores are removed.
[v0.1.0] - 2025-06-27
- add:
containsChecks if a substring is present in the string. Operates on bytes, not code points. - add:
has_prefixChecks if the string starts with the given prefix. Operates on bytes, not code points. - add:
has_suffixChecks if the string ends with the given suffix. Operates on bytes, not code points. - add:
contains_anyChecks if any Unicode code point in the given set is present in the string. Unicode-aware. - add:
count_substringCounts the number of non-overlapping occurrences of a substring in the string. Operates on bytes, not code points. - add:
equal_foldChecks if two strings are equal, ignoring ASCII case. (Full Unicode case folding not yet supported.) - add:
fieldsSplits a string by runs of Unicode whitespace, returning a list of substrings. Returns an empty list if only whitespace. - add:
fields_funcSplits a string at runs of Unicode code points where the given predicate returns true, returning a list of substrings. - add:
indexReturns the byte offset of the first occurrence of a substring in the string, or -1 if not found. - add:
repeatReturns a new string consisting of the given string repeated a specified number of times. Raises an exception if the count is negative. - add:
joinConcatenates a list of strings, inserting the given separator between each element. Returns the empty string if the list is empty.
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
On This Page