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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
//! # `UCase$` Function
//!
//! Returns a `String` that has been converted to uppercase.
//! The "$" suffix indicates this function returns a `String` type.
//!
//! ## Syntax
//!
//! ```vb
//! UCase$(string)
//! ```
//!
//! ## Parameters
//!
//! - **string**: Required. Any valid string expression. If `string` contains `Null`, `Null` is returned.
//!
//! ## Returns
//!
//! Returns a `String` with all lowercase letters converted to uppercase. Numbers and punctuation
//! are unchanged.
//!
//! ## Remarks
//!
//! - `UCase$` converts all lowercase letters in a string to uppercase.
//! - The "$" suffix explicitly indicates the function returns a `String` type rather than a `Variant`.
//! - Only lowercase letters (a-z) are affected; uppercase letters and non-alphabetic characters remain unchanged.
//! - `UCase$` is functionally equivalent to `UCase`, but `UCase$` returns a `String` while `UCase` can return a `Variant`.
//! - For better performance when you know the result is a string, use `UCase$`.
//! - If the argument is `Null`, the function returns `Null`.
//! - The conversion is based on the system locale settings.
//! - For international characters, the behavior depends on the current code page.
//! - The inverse function is `LCase$`, which converts strings to lowercase.
//! - Common use cases include display formatting, SQL keywords, and creating constants.
//!
//! ## Typical Uses
//!
//! 1. **Display formatting** - Format text for display in uppercase
//! 2. **SQL keyword generation** - Create SQL queries with uppercase keywords
//! 3. **Constant generation** - Generate uppercase constant names
//! 4. **File path normalization** - Normalize file paths for case-insensitive systems
//! 5. **Acronym formatting** - Format acronyms and abbreviations
//! 6. **Header text** - Create uppercase headers for reports
//! 7. **Code generation** - Generate uppercase identifiers in code
//!
//! ## Basic Examples
//!
//! ```vb
//! ' Example 1: Simple conversion
//! Dim result As String
//! result = UCase$("hello") ' Returns "HELLO"
//! ```
//!
//! ```vb
//! ' Example 2: Mixed case
//! Dim text As String
//! text = UCase$("Hello World") ' Returns "HELLO WORLD"
//! ```
//!
//! ```vb
//! ' Example 3: With numbers and punctuation
//! Dim mixed As String
//! mixed = UCase$("abc123!@#") ' Returns "ABC123!@#"
//! ```
//!
//! ```vb
//! ' Example 4: Already uppercase
//! Dim upper As String
//! upper = UCase$("ALREADY UPPERCASE") ' Returns "ALREADY UPPERCASE"
//! ```
//!
//! ## Common Patterns
//!
//! ### SQL Keyword Formatting
//! ```vb
//! Function BuildSQLQuery(table As String, field As String) As String
//! BuildSQLQuery = UCase$("SELECT") & " * " & UCase$("FROM") & " " & table
//! End Function
//! ```
//!
//! ### Constant Name Generator
//! ```vb
//! Function GenerateConstantName(baseName As String) As String
//! GenerateConstantName = UCase$(Replace(baseName, " ", "_"))
//! End Function
//! ```
//!
//! ### Acronym Formatter
//! ```vb
//! Function FormatAcronym(text As String) As String
//! FormatAcronym = UCase$(text)
//! End Function
//! ```
//!
//! ### Header Text Generator
//! ```vb
//! Function CreateHeader(title As String) As String
//! CreateHeader = String$(Len(title), "=") & vbCrLf & _
//! UCase$(title) & vbCrLf & _
//! String$(Len(title), "=")
//! End Function
//! ```
//!
//! ### Case-Insensitive Command Comparison
//! ```vb
//! Function ProcessCommand(cmd As String) As Boolean
//! Select Case UCase$(Trim$(cmd))
//! Case "START"
//! ProcessCommand = StartService()
//! Case "STOP"
//! ProcessCommand = StopService()
//! Case "RESTART"
//! ProcessCommand = RestartService()
//! Case Else
//! ProcessCommand = False
//! End Select
//! End Function
//! ```
//!
//! ### File Extension Normalization
//! ```vb
//! Function NormalizeExtension(filename As String) As String
//! Dim ext As String
//! ext = Right$(filename, 4)
//! If UCase$(ext) = ".TXT" Then
//! NormalizeExtension = "Text File"
//! End If
//! End Function
//! ```
//!
//! ### Environment Variable Names
//! ```vb
//! Function GetEnvironmentVar(varName As String) As String
//! GetEnvironmentVar = Environ$(UCase$(varName))
//! End Function
//! ```
//!
//! ### Registry Key Normalization
//! ```vb
//! Function NormalizeRegistryKey(keyName As String) As String
//! NormalizeRegistryKey = UCase$(Trim$(keyName))
//! End Function
//! ```
//!
//! ### Display Name Formatting
//! ```vb
//! Function FormatDisplayName(firstName As String, lastName As String) As String
//! FormatDisplayName = UCase$(lastName) & ", " & firstName
//! End Function
//! ```
//!
//! ### Code Template Generator
//! ```vb
//! Function GenerateEnumMember(memberName As String) As String
//! GenerateEnumMember = " " & UCase$(memberName) & " = " & counter
//! End Function
//! ```
//!
//! ## Advanced Examples
//!
//! ### SQL Query Builder with Uppercase Keywords
//! ```vb
//! Function BuildComplexQuery(table As String, fields As String, whereClause As String) As String
//! Dim sql As String
//!
//! sql = UCase$("SELECT") & " " & fields & " "
//! sql = sql & UCase$("FROM") & " " & table
//!
//! If Len(whereClause) > 0 Then
//! sql = sql & " " & UCase$("WHERE") & " " & whereClause
//! End If
//!
//! BuildComplexQuery = sql
//! End Function
//! ```
//!
//! ### Configuration File Writer
//! ```vb
//! Sub WriteConfigSection(fileNum As Integer, sectionName As String, settings As Collection)
//! Dim key As Variant
//!
//! Print #fileNum, "[" & UCase$(sectionName) & "]"
//!
//! For Each key In settings
//! Print #fileNum, UCase$(key) & "=" & settings(key)
//! Next key
//!
//! Print #fileNum, ""
//! End Sub
//! ```
//!
//! ### Report Header Generator
//! ```vb
//! Function GenerateReportHeader(reportTitle As String, reportDate As String) As String
//! Dim header As String
//! Dim separator As String
//!
//! separator = String$(60, "=")
//! header = separator & vbCrLf
//! header = header & Space$((60 - Len(reportTitle)) \ 2) & UCase$(reportTitle) & vbCrLf
//! header = header & Space$((60 - Len(reportDate)) \ 2) & reportDate & vbCrLf
//! header = header & separator & vbCrLf
//!
//! GenerateReportHeader = header
//! End Function
//! ```
//!
//! ### Macro Name Validator
//! ```vb
//! Function ValidateMacroName(macroName As String) As String
//! Dim validName As String
//! Dim i As Long
//! Dim char As String
//!
//! ' Convert to uppercase and remove invalid characters
//! validName = UCase$(macroName)
//!
//! For i = 1 To Len(validName)
//! char = Mid$(validName, i, 1)
//! If (char >= "A" And char <= "Z") Or _
//! (char >= "0" And char <= "9") Or _
//! char = "_" Then
//! ValidateMacroName = ValidateMacroName & char
//! End If
//! Next i
//! End Function
//! ```
//!
//! ## Error Handling
//!
//! ```vb
//! Function SafeUCase(text As String) As String
//! On Error GoTo ErrorHandler
//!
//! If IsNull(text) Then
//! SafeUCase = ""
//! Exit Function
//! End If
//!
//! SafeUCase = UCase$(text)
//! Exit Function
//!
//! ErrorHandler:
//! SafeUCase = ""
//! End Function
//! ```
//!
//! ## Performance Notes
//!
//! - `UCase$` is a fast operation with minimal overhead
//! - For large strings, the performance is linear with string length
//! - `UCase$` (returns `String`) is slightly faster than `UCase` (returns `Variant`)
//! - When formatting multiple strings, consider caching uppercase versions if reused
//! - For very large datasets, consider using database-level text functions
//!
//! ## Best Practices
//!
//! 1. **Use for display** - Convert to uppercase when formatting for display
//! 2. **Prefer `UCase$` over `UCase`** - Use `UCase$` when you know the result is a string
//! 3. **SQL keywords** - Use uppercase for SQL keywords to improve readability
//! 4. **Handle Null** - Check for `Null` values before calling `UCase$`
//! 5. **Combine with Trim** - Often useful to combine `UCase$` with `Trim$` for cleaner output
//! 6. **Document intent** - Make it clear when uppercase conversion is for display vs. comparison
//! 7. **Consider locale** - Be aware that conversion may vary by system locale
//!
//! ## Comparison with Related Functions
//!
//! | Function | Return Type | Conversion | Use Case |
//! |----------|-------------|------------|----------|
//! | `UCase` | Variant | To uppercase | When working with Variant types |
//! | `UCase$` | String | To uppercase | When result is definitely a string |
//! | `LCase` | Variant | To lowercase | Convert to lowercase (Variant) |
//! | `LCase$` | String | To lowercase | Convert to lowercase (String) |
//! | `StrConv` | String | Various conversions | Complex case conversions |
//!
//! ## Common Use Cases
//!
//! ### HTTP Header Names
//! ```vb
//! Function FormatHTTPHeader(headerName As String, headerValue As String) As String
//! FormatHTTPHeader = UCase$(headerName) & ": " & headerValue
//! End Function
//! ```
//!
//! ### Database Column Names
//! ```vb
//! Function GetColumnName(fieldName As String) As String
//! GetColumnName = UCase$(Replace(fieldName, " ", "_"))
//! End Function
//! ```
//!
//! ### License Key Formatting
//! ```vb
//! Function FormatLicenseKey(key As String) As String
//! ' Format as XXXX-XXXX-XXXX-XXXX
//! Dim upperKey As String
//! upperKey = UCase$(Replace(key, "-", ""))
//!
//! FormatLicenseKey = Mid$(upperKey, 1, 4) & "-" & _
//! Mid$(upperKey, 5, 4) & "-" & _
//! Mid$(upperKey, 9, 4) & "-" & _
//! Mid$(upperKey, 13, 4)
//! End Function
//! ```
//!
//! ### Command Line Argument Parsing
//! ```vb
//! Function ParseArgument(arg As String) As String
//! If Left$(arg, 1) = "/" Or Left$(arg, 1) = "-" Then
//! ParseArgument = UCase$(Mid$(arg, 2))
//! Else
//! ParseArgument = UCase$(arg)
//! End If
//! End Function
//! ```
//!
//! ## Platform Notes
//!
//! - On Windows, `UCase$` respects the system locale for character conversion
//! - Behavior may vary for extended ASCII and international characters
//! - For ASCII characters (a-z), behavior is consistent across all platforms
//! - Some characters may convert differently depending on the active code page
//! - Modern Windows systems handle Unicode characters in `UCase$` operations
//!
//! ## Limitations
//!
//! - Conversion is based on system locale; may not work as expected for all Unicode characters
//! - Returns `Null` if the input is `Null` (unlike some other string functions that error)
//! - Does not handle advanced Unicode normalization or case folding
//! - For true Unicode case folding, more sophisticated methods may be needed
//! - Some special characters may not convert in all locales
use crate::;
/// Converts all lowercase letters in a string to uppercase.
/// The `$` suffix indicates this function returns a `String` type (not `Variant`).
/// Only lowercase letters are converted; uppercase letters and non-letter
/// characters are unchanged. Uses full Unicode case mapping.
///
/// # Arguments
///
/// * `input` — The input string. If empty, an empty string is returned.