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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
//! Various-string manipulation utilities.
use UnicodeXID;
/// Capitalizes the first letter of a given string.
///
/// This function takes a string slice and returns a new `String` with the first
/// letter capitalized. If the string is empty, it returns an empty string.
///
/// # Arguments
///
/// * `s` - A string slice that holds the input string
///
/// # Returns
///
/// A `String` with the first letter capitalized
///
/// # Examples
///
/// ```
/// # use bulloak_syntax::utils::upper_first_letter;
/// let result = upper_first_letter("hello");
/// assert_eq!(result, "Hello");
/// ```
/// Converts the first letter of a given string to lowercase.
///
/// This function takes a string slice and returns a new `String` with the first
/// letter in lowercase. If the string is empty, it returns an empty string.
///
/// # Arguments
///
/// * `s` - A string slice that holds the input string
///
/// # Returns
///
/// A `String` with the first letter in lowercase
///
/// # Examples
///
/// ```
/// # use bulloak_syntax::utils::lower_first_letter;
/// let result = lower_first_letter("Hello");
/// assert_eq!(result, "hello");
/// ```
/// Sanitizes a string to make it a valid identifier.
///
/// This function replaces hyphens with underscores and removes any characters
/// that are not valid in an identifier according to the Unicode Standard Annex
/// #31.
///
/// # Arguments
///
/// * `identifier` - A string slice that holds the input identifier
///
/// # Returns
///
/// A `String` containing the sanitized identifier
///
/// # Examples
///
/// ```
/// # use bulloak_syntax::utils::sanitize;
/// let result = sanitize("my-variable@123");
/// assert_eq!(result, "my_variable123");
/// ```
/// Converts a sentence to pascal case.
///
/// The conversion is done by capitalizing the first letter of each word
/// in the title and removing the spaces. For example, the sentence
/// `when only owner` is converted to the `WhenOnlyOwner` string.
///
/// # Arguments
///
/// * `sentence` - A string slice that holds the input sentence
///
/// # Returns
///
/// A `String` in pascal case
///
/// # Examples
///
/// ```
/// # use bulloak_syntax::utils::to_pascal_case;
/// let result = to_pascal_case("when only owner");
/// assert_eq!(result, "WhenOnlyOwner");
/// ```
/// Repeats a given string a specified number of times.
///
/// # Arguments
///
/// * `s` - A string slice to be repeated
/// * `n` - The number of times to repeat the string
///
/// # Returns
///
/// A `String` containing the repeated string
///
/// # Examples
///
/// ```
/// # use bulloak_syntax::utils::repeat_str;
/// let result = repeat_str("abc", 3);
/// assert_eq!(result, "abcabcabc");
/// ```
/// Returns the singular or plural form of a word based on the count.
///
/// # Arguments
///
/// * `count` - The count to determine which form to use
/// * `singular` - The singular form of the word
/// * `plural` - The plural form of the word
///
/// # Returns
///
/// A string slice containing either the singular or plural form
///
/// # Examples
///
/// ```
/// # use bulloak_syntax::utils::pluralize;
/// assert_eq!(pluralize(1, "apple", "apples"), "apple");
/// assert_eq!(pluralize(2, "apple", "apples"), "apples");
/// ```