Repository navigation
Expand file tree
/
Copy pathstring.pics
More file actions
128 lines (107 loc) · 3.3 KB
/
Copy pathstring.pics
File metadata and controls
128 lines (107 loc) · 3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Module: String
// Provides utility functions for working with string values.
// Wraps native operations for performance where available, and
// supplements with custom implementations (e.g. repeat, pad).
String :: module {
// Function: format
// Formats a string using the given format pattern and argument list.
//
// Parameters:
// fmt - The format string (e.g. "Hello {0}")
// args - A list of values to insert into the format string
//
// Returns:
// A formatted string with placeholders replaced by args
format :: (fmt="", args=[]) = pic_nat_stringformat(fmt, args)
// Function: trim
// Trims leading and trailing whitespace from the input string.
//
// Parameters:
// value - The string to trim
//
// Returns:
// The trimmed string
trim :: (value="") = pic_nat_stringtrim(value)
// Function: uppercase
// Converts a string to all uppercase characters.
//
// Parameters:
// value - The string to convert
//
// Returns:
// A new string with all characters in uppercase
uppercase :: (value="") = pic_nat_stringuppercase(value)
// Function: lowercase
// Converts a string to all lowercase characters.
//
// Parameters:
// value - The string to convert
//
// Returns:
// A new string with all characters in lowercase
lowercase :: (value="") = pic_nat_stringlowercase(value)
// Function: length
// Returns the length (number of characters) in the string.
//
// Parameters:
// xs - The string whose length is to be measured
//
// Returns:
// An integer representing the length of the string
length :: (xs="") = xs.len
// Function: split
// Splits a string into an array based on a delimiter.
//
// Parameters:
// value - The string to split
// delim - The delimiter to use for splitting
//
// Returns:
// An array of substrings
split :: (value="", delim="") = pic_nat_stringsplit(value, delim)
// Function: repeat
// Repeats a string `n` times.
//
// Parameters:
// str - The string to repeat
// n - The number of times to repeat the string
//
// Returns:
// A new string consisting of `str` repeated `n` times
repeat :: (str="", n=0) =
if n <= 0 { "" }
else { str + repeat(str, n - 1) }
// Function: padLeft
// Pads a string from the left to ensure it reaches a total length.
//
// Parameters:
// str - The string to pad
// total - The target total length of the string
// char - The character to pad with (defaults to space)
//
// Returns:
// A new string padded on the left to reach `total` length
padLeft :: (str="", total=0, char=" ") = do {
let padCount = total - String::length(str)
if padCount <= 0 { str }
else { repeat(char, padCount) + str }
}
// Function: padRight
// Pads a string from the right to ensure it reaches a total length.
//
// Parameters:
// str - The string to pad
// total - The target total length of the string
// char - The character to pad with (defaults to space)
//
// Returns:
// A new string padded on the right to reach `total` length
padRight :: (str="", total=0, char=" ") = do {
let padCount = total - String::length(str)
if padCount <= 0 { str }
else { str + repeat(char, padCount) }
}
// Variable: EMPTY
// An empty string constant
EMPTY := ""
}