vb6parse 1.0.1

vb6parse is a library for parsing and analyzing VB6 code, from projects, to controls, to modules, and forms.
Documentation
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
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
//! VB6 `StrConv` Function
//!
//! The `StrConv` function converts a string to a specified format.
//!
//! ## Syntax
//! ```vb6
//! StrConv(string, conversion[, LCID])
//! ```
//!
//! ## Parameters
//! - `string`: Required. String expression to be converted.
//! - `conversion`: Required. Integer specifying the type of conversion to perform. Can be one or more of the following constants (combined with `+` or `Or`):
//!   - `vbUpperCase` (1): Converts the string to uppercase characters
//!   - `vbLowerCase` (2): Converts the string to lowercase characters
//!   - `vbProperCase` (3): Converts the first letter of every word to uppercase
//!   - `vbWide` (4): Converts narrow (single-byte) characters to wide (double-byte) characters
//!   - `vbNarrow` (8): Converts wide (double-byte) characters to narrow (single-byte) characters
//!   - `vbKatakana` (16): Converts Hiragana characters to Katakana characters (Japanese)
//!   - `vbHiragana` (32): Converts Katakana characters to Hiragana characters (Japanese)
//!   - `vbUnicode` (64): Converts the string to Unicode using the default code page
//!   - `vbFromUnicode` (128): Converts the string from Unicode to the default code page
//! - `LCID`: Optional. `LocaleID` value, if different from the system `LocaleID` value. Default is the system `LocaleID`.
//!
//! ## Returns
//! Returns a `Variant` (String) containing the converted string, or a `Variant` (Byte array) when converting to/from Unicode.
//!
//! ## Remarks
//! The `StrConv` function provides powerful string transformation capabilities:
//!
//! - **Case conversion**: `vbUpperCase`, `vbLowerCase`, and `vbProperCase` for text normalization
//! - **Proper case rules**: `vbProperCase` capitalizes first letter after spaces and certain punctuation
//! - **Wide/Narrow conversion**: For Asian languages with double-byte character sets (DBCS)
//! - **Japanese character conversion**: `vbKatakana` and `vbHiragana` for Japanese text
//! - **Unicode conversion**: `vbUnicode` converts string to byte array, `vbFromUnicode` converts byte array to string
//! - **Combining conversions**: Can combine multiple conversions using `+` or `Or` (e.g., `vbUpperCase + vbWide`)
//! - **Return type varies**: String conversions return String, Unicode conversions return Byte array
//! - **Locale-aware**: Proper case conversion respects locale settings
//! - **Performance**: Efficient for bulk text transformation
//!
//! ### Case Conversion Details
//! - `vbUpperCase`: Converts all characters to uppercase using locale rules
//! - `vbLowerCase`: Converts all characters to lowercase using locale rules
//! - `vbProperCase`: Capitalizes first letter of each word, converts rest to lowercase
//!   - Words are delimited by spaces, tabs, and some punctuation
//!   - Preserves existing spacing and punctuation
//!
//! ### Unicode Conversion Details
//! - `vbUnicode`: Converts String to Byte array containing Unicode (UTF-16LE) representation
//!   - Each character becomes 2 bytes
//!   - Useful for binary file operations or API calls
//! - `vbFromUnicode`: Converts Byte array back to String
//!   - Expects byte array in Unicode format
//!   - Reverses `vbUnicode` conversion
//!
//! ### Wide/Narrow Conversion (DBCS)
//! - Relevant for Asian languages (Japanese, Chinese, Korean)
//! - Wide characters occupy two bytes, narrow characters occupy one byte
//! - `vbWide`: Converts half-width to full-width characters
//! - `vbNarrow`: Converts full-width to half-width characters
//!
//! ## Typical Uses
//! 1. **Text Normalization**: Convert user input to consistent case for comparisons
//! 2. **Title Formatting**: Format text in proper case for titles and headings
//! 3. **Data Validation**: Normalize strings before validation or storage
//! 4. **Case-Insensitive Operations**: Convert to uppercase/lowercase for comparisons
//! 5. **Unicode File I/O**: Convert strings to/from Unicode byte arrays for file operations
//! 6. **API Calls**: Convert strings to Unicode byte arrays for Win32 API calls
//! 7. **Japanese Text Processing**: Convert between Hiragana and Katakana
//! 8. **Database Storage**: Normalize case before storing in databases
//!
//! ## Basic Examples
//!
//! ### Example 1: Case Conversion
//! ```vb6
//! Dim text As String
//! Dim result As String
//!
//! text = "Hello World"
//!
//! result = StrConv(text, vbUpperCase)    ' "HELLO WORLD"
//! result = StrConv(text, vbLowerCase)    ' "hello world"
//! result = StrConv(text, vbProperCase)   ' "Hello World"
//!
//! text = "the quick brown fox"
//! result = StrConv(text, vbProperCase)   ' "The Quick Brown Fox"
//! ```
//!
//! ### Example 2: Unicode Conversion
//! ```vb6
//! Dim text As String
//! Dim bytes() As Byte
//! Dim restored As String
//!
//! text = "Hello"
//!
//! ' Convert to Unicode byte array
//! bytes = StrConv(text, vbUnicode)
//! ' bytes contains: 72, 0, 101, 0, 108, 0, 108, 0, 111, 0
//!
//! ' Convert back to string
//! restored = StrConv(bytes, vbFromUnicode)  ' "Hello"
//! ```
//!
//! ### Example 3: Combining Conversions
//! ```vb6
//! Dim text As String
//! Dim result As String
//!
//! text = "hello"
//!
//! ' Combine uppercase with wide conversion (for DBCS)
//! result = StrConv(text, vbUpperCase + vbWide)
//! ```
//!
//! ### Example 4: Proper Case Formatting
//! ```vb6
//! Dim name As String
//! Dim formatted As String
//!
//! name = "JOHN Q. PUBLIC"
//! formatted = StrConv(name, vbProperCase)  ' "John Q. Public"
//!
//! name = "o'brien"
//! formatted = StrConv(name, vbProperCase)  ' "O'brien"
//! ' Note: StrConv doesn't handle special cases like O'Brien
//! ```
//!
//! ## Common Patterns
//!
//! ### Pattern 1: Normalize User Input
//! ```vb6
//! Function NormalizeInput(userInput As String) As String
//!     ' Convert to uppercase for case-insensitive processing
//!     NormalizeInput = StrConv(Trim$(userInput), vbUpperCase)
//! End Function
//! ```
//!
//! ### Pattern 2: Format Name Properly
//! ```vb6
//! Function FormatName(name As String) As String
//!     ' Convert to proper case for display
//!     FormatName = StrConv(Trim$(name), vbProperCase)
//! End Function
//! ```
//!
//! ### Pattern 3: Case-Insensitive Comparison
//! ```vb6
//! Function EqualsIgnoreCase(str1 As String, str2 As String) As Boolean
//!     EqualsIgnoreCase = (StrConv(str1, vbUpperCase) = StrConv(str2, vbUpperCase))
//! End Function
//! ```
//!
//! ### Pattern 4: Write Unicode File
//! ```vb6
//! Sub WriteUnicodeFile(filename As String, text As String)
//!     Dim fileNum As Integer
//!     Dim bytes() As Byte
//!     
//!     bytes = StrConv(text, vbUnicode)
//!     
//!     fileNum = FreeFile
//!     Open filename For Binary As #fileNum
//!     Put #fileNum, , bytes
//!     Close #fileNum
//! End Sub
//! ```
//!
//! ### Pattern 5: Read Unicode File
//! ```vb6
//! Function ReadUnicodeFile(filename As String) As String
//!     Dim fileNum As Integer
//!     Dim bytes() As Byte
//!     Dim fileSize As Long
//!     
//!     fileNum = FreeFile
//!     Open filename For Binary As #fileNum
//!     
//!     fileSize = LOF(fileNum)
//!     ReDim bytes(0 To fileSize - 1)
//!     Get #fileNum, , bytes
//!     Close #fileNum
//!     
//!     ReadUnicodeFile = StrConv(bytes, vbFromUnicode)
//! End Function
//! ```
//!
//! ### Pattern 6: Convert Array of Strings
//! ```vb6
//! Sub ConvertArrayToUpperCase(arr() As String)
//!     Dim i As Integer
//!     
//!     For i = LBound(arr) To UBound(arr)
//!         arr(i) = StrConv(arr(i), vbUpperCase)
//!     Next i
//! End Sub
//! ```
//!
//! ### Pattern 7: Title Case for Sentences
//! ```vb6
//! Function FormatTitle(title As String) As String
//!     Dim result As String
//!     
//!     ' Convert to proper case
//!     result = StrConv(title, vbProperCase)
//!     
//!     ' Handle articles and prepositions (simplified)
//!     result = Replace(result, " A ", " a ")
//!     result = Replace(result, " An ", " an ")
//!     result = Replace(result, " The ", " the ")
//!     result = Replace(result, " Of ", " of ")
//!     result = Replace(result, " In ", " in ")
//!     
//!     FormatTitle = result
//! End Function
//! ```
//!
//! ### Pattern 8: Database Normalization
//! ```vb6
//! Function NormalizeForDatabase(value As String) As String
//!     ' Trim and convert to uppercase for storage
//!     NormalizeForDatabase = StrConv(Trim$(value), vbUpperCase)
//! End Function
//! ```
//!
//! ### Pattern 9: Compare with Wildcard
//! ```vb6
//! Function MatchesPattern(text As String, pattern As String) As Boolean
//!     ' Case-insensitive pattern matching
//!     MatchesPattern = (StrConv(text, vbUpperCase) Like StrConv(pattern, vbUpperCase))
//! End Function
//! ```
//!
//! ### Pattern 10: Extract Unicode Bytes
//! ```vb6
//! Function GetUnicodeBytes(text As String) As String
//!     Dim bytes() As Byte
//!     Dim i As Integer
//!     Dim result As String
//!     
//!     bytes = StrConv(text, vbUnicode)
//!     
//!     result = ""
//!     For i = LBound(bytes) To UBound(bytes)
//!         result = result & CStr(bytes(i)) & " "
//!     Next i
//!     
//!     GetUnicodeBytes = Trim$(result)
//! End Function
//! ```
//!
//! ## Advanced Usage
//!
//! ### Example 1: Text Normalizer Class
//! ```vb6
//! ' Class: TextNormalizer
//! ' Provides text normalization and conversion utilities
//! Option Explicit
//!
//! Public Enum NormalizationMode
//!     UpperCase = 1
//!     LowerCase = 2
//!     ProperCase = 3
//!     NoChange = 0
//! End Enum
//!
//! Private m_Mode As NormalizationMode
//! Private m_TrimSpaces As Boolean
//!
//! Public Sub Initialize(mode As NormalizationMode, trimSpaces As Boolean)
//!     m_Mode = mode
//!     m_TrimSpaces = trimSpaces
//! End Sub
//!
//! Public Function Normalize(text As String) As String
//!     Dim result As String
//!     
//!     result = text
//!     
//!     ' Trim if requested
//!     If m_TrimSpaces Then
//!         result = Trim$(result)
//!     End If
//!     
//!     ' Apply case conversion
//!     Select Case m_Mode
//!         Case UpperCase
//!             result = StrConv(result, vbUpperCase)
//!         Case LowerCase
//!             result = StrConv(result, vbLowerCase)
//!         Case ProperCase
//!             result = StrConv(result, vbProperCase)
//!     End Select
//!     
//!     Normalize = result
//! End Function
//!
//! Public Function NormalizeArray(arr() As String) As String()
//!     Dim result() As String
//!     Dim i As Integer
//!     
//!     ReDim result(LBound(arr) To UBound(arr))
//!     
//!     For i = LBound(arr) To UBound(arr)
//!         result(i) = Normalize(arr(i))
//!     Next i
//!     
//!     NormalizeArray = result
//! End Function
//!
//! Public Function NormalizeCollection(col As Collection) As Collection
//!     Dim result As New Collection
//!     Dim item As Variant
//!     
//!     For Each item In col
//!         result.Add Normalize(CStr(item))
//!     Next item
//!     
//!     Set NormalizeCollection = result
//! End Function
//! ```
//!
//! ### Example 2: Unicode File Handler
//! ```vb6
//! ' Class: UnicodeFileHandler
//! ' Handles reading and writing Unicode text files
//! Option Explicit
//!
//! Public Sub WriteFile(filename As String, text As String, Optional appendMode As Boolean = False)
//!     Dim fileNum As Integer
//!     Dim bytes() As Byte
//!     Dim existingBytes() As Byte
//!     Dim existingSize As Long
//!     Dim newSize As Long
//!     
//!     bytes = StrConv(text, vbUnicode)
//!     fileNum = FreeFile
//!     
//!     If appendMode And Dir(filename) <> "" Then
//!         ' Read existing content
//!         Open filename For Binary As #fileNum
//!         existingSize = LOF(fileNum)
//!         If existingSize > 0 Then
//!             ReDim existingBytes(0 To existingSize - 1)
//!             Get #fileNum, , existingBytes
//!         End If
//!         Close #fileNum
//!         
//!         ' Combine existing and new bytes
//!         newSize = existingSize + UBound(bytes) + 1
//!         ReDim Preserve existingBytes(0 To newSize - 1)
//!         
//!         Dim i As Long
//!         For i = 0 To UBound(bytes)
//!             existingBytes(existingSize + i) = bytes(i)
//!         Next i
//!         
//!         bytes = existingBytes
//!     End If
//!     
//!     ' Write to file
//!     Open filename For Binary As #fileNum
//!     Put #fileNum, , bytes
//!     Close #fileNum
//! End Sub
//!
//! Public Function ReadFile(filename As String) As String
//!     Dim fileNum As Integer
//!     Dim bytes() As Byte
//!     Dim fileSize As Long
//!     
//!     If Dir(filename) = "" Then
//!         Err.Raise 53, , "File not found"
//!     End If
//!     
//!     fileNum = FreeFile
//!     Open filename For Binary As #fileNum
//!     
//!     fileSize = LOF(fileNum)
//!     If fileSize = 0 Then
//!         Close #fileNum
//!         ReadFile = ""
//!         Exit Function
//!     End If
//!     
//!     ReDim bytes(0 To fileSize - 1)
//!     Get #fileNum, , bytes
//!     Close #fileNum
//!     
//!     ReadFile = StrConv(bytes, vbFromUnicode)
//! End Function
//!
//! Public Function ReadLines(filename As String) As String()
//!     Dim content As String
//!     Dim lines() As String
//!     
//!     content = ReadFile(filename)
//!     lines = Split(content, vbCrLf)
//!     
//!     ReadLines = lines
//! End Function
//!
//! Public Sub WriteLines(filename As String, lines() As String)
//!     Dim content As String
//!     content = Join(lines, vbCrLf)
//!     WriteFile filename, content
//! End Sub
//! ```
//!
//! ### Example 3: Case Converter Module
//! ```vb6
//! ' Module: CaseConverter
//! ' Utilities for case conversion and formatting
//! Option Explicit
//!
//! Public Function ToUpper(text As String) As String
//!     ToUpper = StrConv(text, vbUpperCase)
//! End Function
//!
//! Public Function ToLower(text As String) As String
//!     ToLower = StrConv(text, vbLowerCase)
//! End Function
//!
//! Public Function ToProper(text As String) As String
//!     ToProper = StrConv(text, vbProperCase)
//! End Function
//!
//! Public Function ToTitleCase(text As String) As String
//!     ' More sophisticated title case
//!     Dim result As String
//!     Dim words() As String
//!     Dim i As Integer
//!     Dim lowercaseWords As String
//!     
//!     ' Start with proper case
//!     result = StrConv(text, vbProperCase)
//!     
//!     ' Lowercase certain words (not first word)
//!     lowercaseWords = " a an the and but or for nor of in on at to from by "
//!     words = Split(result, " ")
//!     
//!     For i = 1 To UBound(words)  ' Start at 1 to skip first word
//!         If InStr(lowercaseWords, " " & LCase$(words(i)) & " ") > 0 Then
//!             words(i) = LCase$(words(i))
//!         End If
//!     Next i
//!     
//!     ToTitleCase = Join(words, " ")
//! End Function
//!
//! Public Function ToggleCase(text As String) As String
//!     ' Toggle case of each character
//!     Dim i As Integer
//!     Dim char As String
//!     Dim result As String
//!     
//!     result = ""
//!     For i = 1 To Len(text)
//!         char = Mid$(text, i, 1)
//!         If char = UCase$(char) Then
//!             result = result & LCase$(char)
//!         Else
//!             result = result & UCase$(char)
//!         End If
//!     Next i
//!     
//!     ToggleCase = result
//! End Function
//!
//! Public Function IsAllUpper(text As String) As Boolean
//!     IsAllUpper = (text = StrConv(text, vbUpperCase))
//! End Function
//!
//! Public Function IsAllLower(text As String) As Boolean
//!     IsAllLower = (text = StrConv(text, vbLowerCase))
//! End Function
//!
//! Public Function IsProperCase(text As String) As Boolean
//!     IsProperCase = (text = StrConv(text, vbProperCase))
//! End Function
//! ```
//!
//! ### Example 4: String Comparison Helper
//! ```vb6
//! ' Module: StringComparisonHelper
//! ' Case-insensitive comparison utilities
//! Option Explicit
//!
//! Public Function EqualsIgnoreCase(str1 As String, str2 As String) As Boolean
//!     EqualsIgnoreCase = (StrConv(str1, vbUpperCase) = StrConv(str2, vbUpperCase))
//! End Function
//!
//! Public Function StartsWithIgnoreCase(text As String, prefix As String) As Boolean
//!     Dim textUpper As String
//!     Dim prefixUpper As String
//!     
//!     textUpper = StrConv(text, vbUpperCase)
//!     prefixUpper = StrConv(prefix, vbUpperCase)
//!     
//!     StartsWithIgnoreCase = (Left$(textUpper, Len(prefixUpper)) = prefixUpper)
//! End Function
//!
//! Public Function EndsWithIgnoreCase(text As String, suffix As String) As Boolean
//!     Dim textUpper As String
//!     Dim suffixUpper As String
//!     
//!     textUpper = StrConv(text, vbUpperCase)
//!     suffixUpper = StrConv(suffix, vbUpperCase)
//!     
//!     EndsWithIgnoreCase = (Right$(textUpper, Len(suffixUpper)) = suffixUpper)
//! End Function
//!
//! Public Function ContainsIgnoreCase(text As String, searchValue As String) As Boolean
//!     Dim textUpper As String
//!     Dim searchUpper As String
//!     
//!     textUpper = StrConv(text, vbUpperCase)
//!     searchUpper = StrConv(searchValue, vbUpperCase)
//!     
//!     ContainsIgnoreCase = (InStr(textUpper, searchUpper) > 0)
//! End Function
//!
//! Public Function IndexOfIgnoreCase(text As String, searchValue As String) As Long
//!     Dim textUpper As String
//!     Dim searchUpper As String
//!     
//!     textUpper = StrConv(text, vbUpperCase)
//!     searchUpper = StrConv(searchValue, vbUpperCase)
//!     
//!     IndexOfIgnoreCase = InStr(textUpper, searchUpper)
//! End Function
//!
//! Public Function ReplaceIgnoreCase(text As String, findText As String, _
//!                                   replaceText As String) As String
//!     Dim result As String
//!     Dim pos As Long
//!     Dim lastPos As Long
//!     Dim textUpper As String
//!     Dim findUpper As String
//!     
//!     result = ""
//!     lastPos = 1
//!     textUpper = StrConv(text, vbUpperCase)
//!     findUpper = StrConv(findText, vbUpperCase)
//!     
//!     pos = InStr(lastPos, textUpper, findUpper)
//!     Do While pos > 0
//!         result = result & Mid$(text, lastPos, pos - lastPos) & replaceText
//!         lastPos = pos + Len(findText)
//!         pos = InStr(lastPos, textUpper, findUpper)
//!     Loop
//!     
//!     result = result & Mid$(text, lastPos)
//!     ReplaceIgnoreCase = result
//! End Function
//! ```
//!
//! ## Error Handling
//! The `StrConv` function can raise the following errors:
//!
//! - **Error 5 (Invalid procedure call or argument)**: If `conversion` constant is invalid or incompatible combinations are used
//! - **Error 13 (Type mismatch)**: If `string` argument cannot be converted to a string
//! - **Error 6 (Overflow)**: In rare cases with very large strings or byte arrays
//!
//! ## Performance Notes
//! - Very fast for case conversions (uppercase, lowercase, proper case)
//! - Unicode conversions are efficient but create byte arrays (memory overhead)
//! - Proper case conversion slower than upper/lower case (more complex rules)
//! - Wide/Narrow conversions only relevant for DBCS environments
//! - Consider caching converted values if used repeatedly
//! - For simple uppercase/lowercase, `UCase$` and `LCase$` may be slightly faster
//!
//! ## Best Practices
//! 1. **Use for normalization** before comparisons or storage
//! 2. **Combine with Trim$** to remove leading/trailing spaces before conversion
//! 3. **Handle proper case limitations** - doesn't handle special cases like "O'Brien" or "`McDonald`"
//! 4. **Cache conversion constants** in variables for clarity (e.g., `Const UPPER_CASE = vbUpperCase`)
//! 5. **Use Unicode conversion** for binary file I/O or API calls requiring Unicode
//! 6. **Test with locale-specific text** when using proper case or locale-dependent conversions
//! 7. **Document conversion type** in comments when not obvious from context
//! 8. **Consider alternatives** - `UCase$`, `LCase$` for simple case conversion (slightly faster)
//! 9. **Validate conversion parameter** when accepting user input
//! 10. **Handle byte array return** appropriately when using `vbUnicode` conversion
//!
//! ## Comparison Table
//!
//! | Function | Purpose | Returns | Locale-Aware |
//! |----------|---------|---------|--------------|
//! | `StrConv` | Multiple conversions | String or Byte array | Yes |
//! | `UCase$` | Uppercase only | String | Yes |
//! | `LCase$` | Lowercase only | String | Yes |
//! | `Format$` | General formatting | String | Yes |
//!
//! ## Platform Notes
//! - Available in VB6 and VBA
//! - Not available in `VBScript`
//! - `vbWide`/`vbNarrow` primarily for Asian language environments
//! - `vbKatakana`/`vbHiragana` only meaningful for Japanese text
//! - Unicode conversion uses UTF-16LE (Windows default)
//! - Proper case rules may vary by locale
//! - LCID parameter rarely used (defaults to system locale)
//!
//! ## Limitations
//! - Proper case doesn't handle special cases (O'Brien, `McDonald`, etc.)
//! - Cannot specify custom word delimiters for proper case
//! - Unicode conversion always uses UTF-16LE (cannot specify encoding)
//! - No direct support for other Unicode formats (UTF-8, UTF-32)
//! - Wide/Narrow conversion limited to DBCS environments
//! - Cannot combine incompatible conversions (e.g., `vbUpperCase + vbLowerCase`)
//! - No validation of byte array format when using `vbFromUnicode`
//! - LCID parameter has limited practical use

#[cfg(test)]
mod tests {
    use crate::*;

    #[test]
    fn strconv_basic() {
        let source = r#"
Sub Test()
    result = StrConv("Hello", vbUpperCase)
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/string/strconv");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn strconv_variable_assignment() {
        let source = r"
Sub Test()
    Dim result As String
    result = StrConv(text, vbUpperCase)
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/string/strconv");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn strconv_lowercase() {
        let source = r"
Sub Test()
    result = StrConv(input, vbLowerCase)
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/string/strconv");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn strconv_propercase() {
        let source = r"
Sub Test()
    result = StrConv(name, vbProperCase)
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/string/strconv");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn strconv_unicode() {
        let source = r"
Sub Test()
    Dim bytes() As Byte
    bytes = StrConv(text, vbUnicode)
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/string/strconv");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn strconv_from_unicode() {
        let source = r"
Sub Test()
    result = StrConv(byteArray, vbFromUnicode)
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/string/strconv");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn strconv_if_statement() {
        let source = r#"
Sub Test()
    If StrConv(input, vbUpperCase) = "YES" Then
        MsgBox "Confirmed"
    End If
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/string/strconv");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn strconv_for_loop() {
        let source = r"
Sub Test()
    For i = LBound(arr) To UBound(arr)
        arr(i) = StrConv(arr(i), vbUpperCase)
    Next i
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/string/strconv");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn strconv_function_return() {
        let source = r"
Function ToUpper(text As String) As String
    ToUpper = StrConv(text, vbUpperCase)
End Function
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/string/strconv");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn strconv_comparison() {
        let source = r#"
Sub Test()
    If StrConv(str1, vbUpperCase) = StrConv(str2, vbUpperCase) Then
        MsgBox "Equal"
    End If
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/string/strconv");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn strconv_with_trim() {
        let source = r"
Sub Test()
    result = StrConv(Trim$(input), vbProperCase)
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/string/strconv");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn strconv_select_case() {
        let source = r#"
Sub Test()
    Select Case StrConv(command, vbUpperCase)
        Case "QUIT"
            Exit Sub
        Case "HELP"
            ShowHelp
    End Select
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/string/strconv");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn strconv_array_assignment() {
        let source = r"
Sub Test()
    normalized(i) = StrConv(original(i), vbUpperCase)
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/string/strconv");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn strconv_function_argument() {
        let source = r"
Sub Test()
    Call ProcessText(StrConv(input, vbProperCase))
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/string/strconv");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn strconv_concatenation() {
        let source = r#"
Sub Test()
    message = "Hello " & StrConv(name, vbProperCase)
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/string/strconv");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn strconv_do_while() {
        let source = r#"
Sub Test()
    Do While StrConv(input, vbUpperCase) <> "DONE"
        input = GetInput()
    Loop
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/string/strconv");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn strconv_do_until() {
        let source = r#"
Sub Test()
    Do Until StrConv(status, vbUpperCase) = "READY"
        Wait 100
    Loop
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/string/strconv");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn strconv_while_wend() {
        let source = r#"
Sub Test()
    While StrConv(cmd, vbUpperCase) <> "EXIT"
        cmd = ProcessCommand()
    Wend
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/string/strconv");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn strconv_iif() {
        let source = r"
Sub Test()
    result = IIf(mode = 1, StrConv(text, vbUpperCase), StrConv(text, vbLowerCase))
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/string/strconv");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn strconv_with_statement() {
        let source = r"
Sub Test()
    With obj
        .Name = StrConv(.Name, vbProperCase)
    End With
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/string/strconv");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn strconv_parentheses() {
        let source = r"
Sub Test()
    result = (StrConv(str1, vbUpperCase) = StrConv(str2, vbUpperCase))
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/string/strconv");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn strconv_error_handling() {
        let source = r#"
Sub Test()
    On Error Resume Next
    result = StrConv(varValue, vbProperCase)
    If Err.Number <> 0 Then
        result = ""
    End If
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/string/strconv");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn strconv_property_assignment() {
        let source = r"
Sub Test()
    obj.Title = StrConv(rawTitle, vbProperCase)
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/string/strconv");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn strconv_msgbox() {
        let source = r#"
Sub Test()
    MsgBox StrConv("warning: system error", vbProperCase)
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/string/strconv");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn strconv_debug_print() {
        let source = r"
Sub Test()
    Debug.Print StrConv(output, vbUpperCase)
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/string/strconv");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn strconv_numeric_constant() {
        let source = r"
Sub Test()
    result = StrConv(text, 1)
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/string/strconv");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn strconv_combined_conversion() {
        let source = r"
Sub Test()
    result = StrConv(text, vbUpperCase + vbWide)
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/string/strconv");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }
}