Lumesh String Processing Module Documentation
Module Path: string
Function Description: Provides comprehensive string manipulation capabilities, including character property detection, text splitting, format conversion, and advanced processing. Supports two calling styles:
- Functional Call:
string.func(arg0, arg1...)
- Imperative Call:
string.func arg0 arg1...
Function Categories and Detailed Description
I. Character Property Detection
string.is_empty
- Functionality: Checks if the string is entirely composed of whitespace characters.
- Parameters:
text: string
- Return Value:
boolean
- Example:
string.is_empty "" # => true
string.is_whitespace
- Functionality: Checks if the string is entirely composed of whitespace characters.
- Parameters:
text: string
- Return Value:
boolean
- Example:
string.is_whitespace " \t\n" # => true
string.is_alpha
- Functionality: Checks if the string consists entirely of letters.
- Parameters:
text: string
- Return Value:
boolean
- Example:
string.is_alpha "Hello" # => true
string.is_alphanumeric
- Functionality: Checks if the string consists entirely of letters or digits.
- Parameters:
text: string
- Return Value:
boolean
- Example:
string.is_alphanumeric "R2D2" # => true
string.is_numeric
- Functionality: Checks if the string consists entirely of digits.
- Parameters:
text: string
- Return Value:
boolean
- Example:
string.is_numeric "³Ⅳ" # => true (supports Unicode digits)
string.is_lower
- Functionality: Checks if the string consists entirely of lowercase letters.
- Parameters:
text: string
- Return Value:
boolean
- Example:
string.is_lower "hello" # => true
string.is_upper
- Functionality: Checks if the string consists entirely of uppercase letters.
- Parameters:
text: string
- Return Value:
boolean
- Example:
string.is_upper "HELLO" # => true
string.is_title
- Functionality: Checks if the string is in title case (first letter of each word capitalized).
- Parameters:
text: string
- Return Value:
boolean
- Example:
string.is_title "Hello World" # => true
II. Substring Checks
string.starts_with
- Functionality: Checks if the string starts with the specified substring.
- Parameters:
prefix: string
text: string
- Return Value:
boolean
- Example:
string.starts_with "He" "Hello" # => true
string.ends_with
- Functionality: Checks if the string ends with the specified substring.
- Parameters:
suffix: string
text: string
- Return Value:
boolean
- Example:
string.ends_with "lo" "Hello" # => true
string.contains
- Functionality: Checks if the string contains the specified substring.
- Parameters:
substring: string
text: string
- Return Value:
boolean
- Example:
string.contains "ell" "Hello" # => true
III. Text Splitting
string.split
- Functionality: Splits the string by a delimiter.
- Parameters:
delimiter: string
text: string
- Return Value:
[part1, part2, ...]
- Example:
string.split ";" "a;b;c" # => ["a", "b", "c"]
string.split_at
- Functionality: Splits the string at the specified index.
- Parameters:
index: integer
text: string
- Return Value:
[left_part, right_part]
- Example:
string.split_at 2 "Hello" # => ["He", "llo"]
string.chars
- Functionality: Splits the string into a list of characters.
- Parameters:
text: string
- Return Value:
[char1, char2, ...]
- Example:
string.chars "ABC" # => ["A", "B", "C"]
string.words
- Functionality: Splits the string into words by whitespace.
- Parameters:
text: string
- Return Value:
[word1, word2, ...]
- Example:
string.words "hello world" # => ["hello", "world"]
string.lines
- Functionality: Splits the text into lines by newline characters.
- Parameters:
text: string
- Return Value:
[line1, line2, ...]
- Example:
string.lines "a\nb" # => ["a", "b"]
string.paragraphs
- Functionality: Splits the text into paragraphs by empty lines.
- Parameters:
text: string
- Return Value:
[para1, para2, ...]
- Example:
string.paragraphs "a\n\nb" # => ["a", "b"]
IV. Text Modification
string.repeat
- Functionality: Repeats the string a specified number of times.
- Parameters:
count: integer
text: string
- Return Value:
string
- Example:
string.repeat 3 "a" # => "aaa"
string.replace
- Functionality: Replaces all matching substrings.
- Parameters:
from: string
to: string
text: string
- Return Value:
string
- Example:
string.replace "l" "x" "hello" # => "hexxo"
string.substring
- Functionality: Extracts a substring.
- Parameters:
start: integer
(supports negative indexing)end: integer
(optional, supports negative indexing)text: string
- Return Value:
string
- Example:
string.substring 1 3 "Hello" # => "el"
string.substring -3 -1 "Hello" # => "ll"
string.remove_prefix
- Functionality: Removes the prefix if it exists.
- Parameters:
prefix: string
text: string
- Return Value:
string
- Example:
string.remove_prefix "He" "Hello" # => "llo"
string.remove_suffix
- Functionality: Removes the suffix if it exists.
- Parameters:
suffix: string
text: string
- Return Value:
string
- Example:
string.remove_suffix "lo" "Hello" # => "Hel"
string.trim
- Functionality: Removes whitespace from both ends.
- Parameters:
text: string
- Return Value:
string
- Example:
string.trim " a " # => "a"
string.trim_start
- Functionality: Removes whitespace from the start.
- Parameters:
text: string
- Return Value:
string
- Example:
string.trim_start " a" # => "a"
string.trim_end
- Functionality: Removes whitespace from the end.
- Parameters:
text: string
- Return Value:
string
- Example:
string.trim_end "a " # => "a"
string.to_lower
- Functionality: Converts to lowercase.
- Parameters:
text: string
- Return Value:
string
- Example:
string.to_lower "HeLLo" # => "hello"
string.to_upper
- Functionality: Converts to uppercase.
- Parameters:text: string
- Return Value:string
- Example:string.to_upper "hello" # => "HELLO"
string.to_title
- Functionality: Converts to title case.
- Parameters:text: string
- Return Value:string
- Example:string.to_title "hello world" # => "Hello World"
V. Advanced Features
string.caesar
- Functionality: Encrypts using Caesar cipher.
- Parameters:
shift: integer
(optional, default is 13)text: string
- Return Value:
string
- Example:
string.caesar "ABC" # => "NOP" (default shift 13)
string.caesar 13 "ABC" # => "DEF"
string.get_width
- Functionality: Gets the maximum line width of the text.
- Parameters:
text: string
- Return Value:
integer
- Example:
string.get_width "a\nbb\nccc" # => 3
General Rules
Index Handling:
- Positive indices start at 0.
- Throws an exception for out-of-bounds indices.
Whitespace Definition:
- Includes spaces, tabs, newline characters, and other Unicode whitespace characters.
Error Handling:
- Throws an exception for parameter type errors.