-
Notifications
You must be signed in to change notification settings - Fork 72
/
ConvertToPascalCase.ahk
68 lines (48 loc) · 1.39 KB
/
ConvertToPascalCase.ahk
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
ConvertToPascalCase(ByRef fnCopiedText)
{
; converts object name from loser_case to PascalCase
; MsgBox fnCopiedText: %fnCopiedText%
; declare local, global, static variables
Try
{
; set default return value
ReturnValue := 0 ; success
; validate parameters
If !fnCopiedText
Throw, Exception("fnCopiedText was empty")
; initialise variables
; convert to title case
StringLower, NewString, fnCopiedText, T
; remove underscores and capitalize
PCRE := "imS)([_])(\w)"
NewString := RegExReplace(NewString,PCRE,"$U2")
; capitalize
PCRE := "imS)([ ,\(])(\[?)([\@\#])?(\w)"
NewString := RegExReplace(NewString,PCRE,"$1$2$3$U4")
; id -> Id
PCRE := "imS)(.*)(id)$"
NewString := RegExReplace(NewString,PCRE,"$1Id")
; kb -> KB etc.
PCRE := "imS)(.*)((k|m|g|t)b)$"
NewString := RegExReplace(NewString,PCRE,"$1$U2")
; remove spaces
StringReplace, NewString, NewString, %A_Space%,, All
; set the value of the ByRef parameter
fnCopiedText := NewString
}
Catch, ThrownValue
{
ReturnValue := !ReturnValue
CatchHandler(A_ThisFunc,ThrownValue.Message,ThrownValue.What,ThrownValue.Extra,ThrownValue.File,ThrownValue.Line,0,0,0)
}
Finally
{
}
; return
Return ReturnValue
}
/* ; testing
params := "hello there matey"
ReturnValue := ConvertToPascalCase(params)
MsgBox, ConvertToPascalCase`n`nReturnValue: %ReturnValue%`n`nparams: %params%
*/