-
Notifications
You must be signed in to change notification settings - Fork 0
/
Capsulate.ahk
656 lines (567 loc) · 20.6 KB
/
Capsulate.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
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
#Requires AutoHotkey v2.0
#SingleInstance Force
SCRIPT_VERSION := "0.7.0"
; Initialize global variables
global CACHED_CONFIG := LoadConfiguration()
global CAPS_LOCK_TIMEOUT := CACHED_CONFIG["CapsLockTimeout"]
global DOUBLE_CLICK_COUNT := CACHED_CONFIG["DoubleClickCount"]
global TOOLTIP_POSITION := CACHED_CONFIG["ToolTipPosition"]
global DOUBLE_CLICK_ACTION := CACHED_CONFIG["DoubleClickAction"]
global capsLockPressed := false
global waitingForChord := false
global capsLockTimer := 0
global capsLockCount := 0
SetCapsLockState "AlwaysOff"
SetTrayIcon()
SetTrayIcon() {
iconFile := IsWindowsDarkTheme()
? A_ScriptDir . "\capsulate-dark.png"
: A_ScriptDir . "\capsulate-light.png"
TraySetIcon(iconFile)
}
IsWindowsDarkTheme() {
regKey := "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize"
return !RegRead(regKey, "AppsUseLightTheme")
}
A_IconTip := "Capsulate v" . SCRIPT_VERSION . " - Enhance Your Caps Lock"
trayMenu := A_TrayMenu
trayMenu.Delete()
trayMenu.Add("Capsulate v" . SCRIPT_VERSION, (*) => {})
trayMenu.Disable("Capsulate v" . SCRIPT_VERSION)
trayMenu.Add()
trayMenu.Add("Check for Updates", CheckForUpdates)
trayMenu.Add("Run at Startup", (*) => ToggleStartup())
trayMenu.Add()
trayMenu.Add("Configuration`tCapsLock+Alt+C", (*) => ShowUnifiedConfigGUI())
trayMenu.Add("Restart Script `tCapsLock+Alt+R", (*) => Reload())
trayMenu.Add("Exit", (*) => ExitApp())
SetTimer SetTrayIcon, 5000
if (CheckLatestVersion()) {
ShowTooltip("A new version is available!")
}
*CapsLock:: {
global capsLockPressed, capsLockTimer
capsLockPressed := true
capsLockTimer := A_TickCount
}
*CapsLock up:: {
global capsLockPressed, capsLockTimer, capsLockCount, CAPS_LOCK_TIMEOUT, DOUBLE_CLICK_COUNT
capsLockPressed := false
elapsedTime := A_TickCount - capsLockTimer
if (elapsedTime < CAPS_LOCK_TIMEOUT) {
capsLockCount++
if (capsLockCount = DOUBLE_CLICK_COUNT) {
SendInput DOUBLE_CLICK_ACTION
capsLockCount := 0
} else {
SetTimer () => (capsLockCount := 0), -CAPS_LOCK_TIMEOUT
}
} else {
capsLockCount := 1
}
capsLockTimer := A_TickCount
}
^CapsLock:: SetCapsLockState GetKeyState("CapsLock", "T") ? "AlwaysOff" : "AlwaysOn"
#HotIf capsLockPressed
+Left:: Send "#+{Left}"
+Right:: Send "#+{Right}"
1:: LaunchShortcut("1")
2:: LaunchShortcut("2")
3:: LaunchShortcut("3")
4:: LaunchShortcut("4")
5:: LaunchShortcut("5")
6:: LaunchShortcut("6")
7:: LaunchShortcut("7")
8:: LaunchShortcut("8")
9:: LaunchShortcut("9")
0:: LaunchShortcut("0")
!c:: ShowUnifiedConfigGUI()
!r:: Reload()
Up:: SendInput "{Volume_Up}"
Down:: SendInput "{Volume_Down}"
BackSpace:: SendInput "{Volume_Mute}"
Delete:: Run "*RunAs cleanmgr"
Left:: Send "#^{Left}"
Right:: Send "#^{Right}"
Space:: Send "^!{Space}"
T:: Run "taskmgr"
W:: Run "ms-settings:windowsupdate"
C:: Send "+#c"
X:: RestartXMouseButtonControl()
E:: ExpandText()
P:: GeneratePassword()
K:: {
global waitingForChord
waitingForChord := true
ShowTooltip("Waiting for a second key of chord...")
SetTimer () => ToolTip(), -2000
}
#HotIf waitingForChord
L:: ConvertCase("lower")
U:: ConvertCase("upper")
C:: ConvertCase("camel")
T:: ConvertCase("title")
Space:: ConvertCase("trim")
#HotIf
GetSelectedText() {
static lastOperation := 0
currentTime := A_TickCount
; Throttle clipboard operations
if (currentTime - lastOperation < 100) {
Sleep 50
}
try {
savedClipboard := ClipboardAll()
A_Clipboard := ""
Send "^c"
if !ClipWait(0.5) {
throw Error("Failed to get clipboard content")
}
selectedText := A_Clipboard
A_Clipboard := savedClipboard
lastOperation := A_TickCount
return selectedText
} catch Error as err {
ShowTooltip("Error getting selected text: " err.Message)
return ""
}
}
LaunchShortcut(key) {
path := IniRead(A_ScriptDir . "\config.ini", "Shortcuts", key, "")
if (path != "")
Run(path)
}
ExpandText() {
word := GetWordAtCursor()
ShowTooltip("Word captured: " . word)
expansion := GetExpansion(word)
if (expansion) {
ShowTooltip("Expansion found: " . expansion)
SendInput "{BackSpace " . StrLen(word) . "}"
SendInput expansion
} else {
ShowTooltip("No expansion found for: " . word)
}
}
GetWordAtCursor() {
savedClipboard := ClipboardAll
A_Clipboard := ""
SendInput "^{Left}^+{Right}^c"
ClipWait(0.5)
word := A_Clipboard
A_Clipboard := savedClipboard
return Trim(word)
}
GetExpansion(word) {
return IniRead(A_ScriptDir . "\expansions.ini", "Expansions", word, "")
}
ShowUnifiedConfigGUI() {
global CACHED_CONFIG
configGui := Gui(, "Capsulate Configuration")
configGui.SetFont("s9", "Segoe UI")
tabs := configGui.Add("Tab3", "w400 h400", ["General", "Text Expander"])
tabs.UseTab(1)
configGui.Add("Text", "x20 y40 w150", "Caps Lock Timeout:")
timeoutEdit := configGui.Add("Edit", "x170 y40 w50", CACHED_CONFIG["CapsLockTimeout"])
configGui.Add("Text", "x20 y70 w150", "Double Click Count:")
doubleClickCountEdit := configGui.Add("Edit", "x170 y70 w50", CACHED_CONFIG["DoubleClickCount"])
configGui.Add("Text", "x20 y100 w150", "Tooltip Position:")
tooltipPositionDropdown := configGui.Add("DropDownList", "vTooltipPosition x170 y100 w100", ["Near Mouse",
"Near Tray"])
tooltipPositionDropdown.Choose(CACHED_CONFIG["ToolTipPosition"] ? "Near Mouse" : "Near Tray")
configGui.Add("Text", "x20 y130 w150", "Double Click Action:")
doubleClickActionEdit := configGui.Add("Edit", "x170 y130 w200", CACHED_CONFIG["DoubleClickAction"])
tabs.UseTab(2)
configGui.Add("Text", "x20 y40", "Abbreviation:")
abbrevEdit := configGui.Add("Edit", "x20 y60 w100")
configGui.Add("Text", "x20 y90", "Expansion:")
expansionEdit := configGui.Add("Edit", "x20 y110 w200 h60")
lv := configGui.Add("ListView", "x20 y180 w360 h150", ["Abbreviation", "Expansion"])
PopulateExpansionsList(lv)
configGui.Add("Button", "x20 y340 w100", "Add/Update").OnEvent("Click", (*) => SaveExpansion(abbrevEdit,
expansionEdit, lv))
configGui.Add("Button", "x130 y340 w100", "Delete").OnEvent("Click", (*) => DeleteExpansion(lv))
tabs.UseTab()
configGui.Add("Button", "x20 y410 w100", "Save").OnEvent("Click", (*) => SaveUnifiedConfig(configGui, timeoutEdit,
doubleClickCountEdit, tooltipPositionDropdown, doubleClickActionEdit))
configGui.Add("Button", "x130 y410 w100", "Cancel").OnEvent("Click", (*) => configGui.Destroy())
configGui.Show()
}
SaveUnifiedConfig(configGui, timeoutEdit, doubleClickCountEdit, tooltipPositionDropdown, doubleClickActionEdit) {
global CACHED_CONFIG, CAPS_LOCK_TIMEOUT, DOUBLE_CLICK_COUNT, TOOLTIP_POSITION, DOUBLE_CLICK_ACTION
CACHED_CONFIG["CapsLockTimeout"] := timeoutEdit.Value
CACHED_CONFIG["DoubleClickCount"] := doubleClickCountEdit.Value
CACHED_CONFIG["ToolTipPosition"] := tooltipPositionDropdown.Value = "Near Mouse" ? 1 : 0
CACHED_CONFIG["DoubleClickAction"] := doubleClickActionEdit.Value
CAPS_LOCK_TIMEOUT := CACHED_CONFIG["CapsLockTimeout"]
DOUBLE_CLICK_COUNT := CACHED_CONFIG["DoubleClickCount"]
TOOLTIP_POSITION := CACHED_CONFIG["ToolTipPosition"]
DOUBLE_CLICK_ACTION := CACHED_CONFIG["DoubleClickAction"]
configFile := A_ScriptDir . "\config.ini"
IniWrite(CACHED_CONFIG["CapsLockTimeout"], configFile, "General", "CapsLockTimeout")
IniWrite(CACHED_CONFIG["DoubleClickCount"], configFile, "General", "DoubleClickCount")
IniWrite(CACHED_CONFIG["ToolTipPosition"], configFile, "General", "ToolTipPosition")
IniWrite(CACHED_CONFIG["DoubleClickAction"], configFile, "General", "DoubleClickAction")
loop 10 {
key := A_Index - 1
path := IniRead(A_ScriptDir . "\config.ini", "Shortcuts", key, "")
if (path != "")
IniWrite(path, configFile, "Shortcuts", key)
}
configGui.Destroy()
ShowTooltip("Configuration saved successfully!")
}
PopulateExpansionsList(lv) {
lv.Delete()
expansionsFile := A_ScriptDir . "\expansions.ini"
if (FileExist(expansionsFile)) {
expansions := IniRead(expansionsFile, "Expansions")
loop parse, expansions, "`n", "`r" {
parts := StrSplit(A_LoopField, "=")
if (parts.Length == 2)
lv.Add(parts[1], parts[2])
}
}
}
SaveExpansion(abbrevEdit, expansionEdit, lv) {
abbrev := abbrevEdit.Value
expansion := expansionEdit.Value
if (abbrev != "" and expansion != "") {
IniWrite(expansion, A_ScriptDir . "\expansions.ini", "Expansions", abbrev)
PopulateExpansionsList(lv)
MsgBox "Expansion saved successfully!"
} else {
MsgBox "Please enter both abbreviation and expansion."
}
}
DeleteExpansion(lv) {
if (row := lv.GetNext()) {
IniDelete(A_ScriptDir . "\expansions.ini", "Expansions", lv.GetText(row, 1))
lv.Delete(row)
} else {
MsgBox "Please select an expansion to delete."
}
}
LoadConfiguration() {
try {
configFile := A_ScriptDir . "\config.ini"
if !FileExist(configFile) {
CreateDefaultConfig(configFile)
}
return Map(
"CapsLockTimeout", IniRead(configFile, "General", "CapsLockTimeout", 300),
"DoubleClickCount", IniRead(configFile, "General", "DoubleClickCount", 2),
"ToolTipPosition", IniRead(configFile, "General", "ToolTipPosition", 1),
"DoubleClickAction", IniRead(configFile, "General", "DoubleClickAction", "{Esc}")
)
} catch Error as err {
MsgBox "Error loading configuration: " err.Message
ExitApp
}
}
CreateDefaultConfig(configFile) {
FileAppend "
(
[General]
CapsLockTimeout=300
DoubleClickCount=2
ToolTipPosition=1
DoubleClickAction={Esc}
)",
configFile
}
ShowTooltip(text) {
static tooltipGui := 0
if (!tooltipGui) {
tooltipGui := Gui("+AlwaysOnTop -Caption +ToolWindow")
tooltipGui.BackColor := "0x202020"
tooltipGui.Opt("+E0x20")
tooltipGui.MarginX := 16
tooltipGui.MarginY := 12
tooltipGui.SetFont("s10 cWhite", "Segoe UI")
tooltipGui.Add("Text", "vTooltipText", text)
} else {
tooltipGui["TooltipText"].Value := text
}
if (TOOLTIP_POSITION = 1) {
MouseGetPos(&mouseX, &mouseY)
xPos := mouseX + 10
yPos := mouseY + 10
} else {
xPos := A_ScreenWidth - 250
yPos := A_ScreenHeight - 100
}
tooltipGui.Show(Format("x{} y{} AutoSize", xPos, yPos))
SetTimer () => tooltipGui.Hide(), -2000
}
ToggleStartup() {
startupFolder := A_Startup . "\Capsulate.lnk"
if (FileExist(startupFolder)) {
FileDelete startupFolder
trayMenu.Uncheck("Run at Startup")
ShowTooltip("Capsulate removed from startup")
} else {
FileCreateShortcut(A_ScriptFullPath, startupFolder)
trayMenu.Check("Run at Startup")
ShowTooltip("Capsulate added to startup")
}
}
if (FileExist(A_Startup . "\Capsulate.lnk"))
trayMenu.Check("Run at Startup")
GeneratePassword() {
chars := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+-=[]{}|;:,.<>?"
password := ""
loop 16 {
randomIndex := Random(1, StrLen(chars))
password .= SubStr(chars, randomIndex, 1)
}
A_Clipboard := password
ShowTooltip("Password generated and copied to clipboard!")
}
ConvertCase(caseType) {
global waitingForChord
waitingForChord := false
ToolTip()
savedClipboard := ClipboardAll
A_Clipboard := ""
Send "^c"
if !ClipWait(0.5) {
ShowTooltip("No text selected")
return
}
text := A_Clipboard
if (text = "") {
ShowTooltip("Selected text is empty")
return
}
switch caseType {
case "lower":
convertedText := StrLower(text)
case "upper":
convertedText := StrUpper(text)
case "camel":
convertedText := ToCamelCase(text)
case "title":
convertedText := ToTitleCase(text)
case "trim":
convertedText := Trim(text)
}
if (convertedText != "") {
A_Clipboard := convertedText
Send "^v"
ShowTooltip("Text converted to " . caseType)
} else {
ShowTooltip("Failed to convert text")
}
Sleep 100
A_Clipboard := savedClipboard
}
ToCamelCase(str) {
result := ""
nextUpper := false
loop parse, str {
if (A_LoopField = " " or A_LoopField = "_" or A_LoopField = "-") {
nextUpper := true
} else if (nextUpper) {
result .= StrUpper(A_LoopField)
nextUpper := false
} else {
result .= StrLower(A_LoopField)
}
}
return result
}
ToTitleCase(str) {
return StrTitle(str)
}
RestartXMouseButtonControl() {
ProcessClose("XMouseButtonControl.exe")
Run("XMouseButtonControl.exe")
ShowTooltip("XMouseButtonControl restarted")
}
CheckLatestVersion() {
try {
whr := ComObject("WinHttp.WinHttpRequest.5.1")
url := "https://api.github.com/repos/yourusername/Capsulate/releases/latest"
whr.Open("GET", url, true)
whr.Send()
whr.WaitForResponse()
if (whr.Status = 200) {
response := Jxon_Load(whr.ResponseText)
latestVersion := response["tag_name"]
return latestVersion > SCRIPT_VERSION
}
return false
} catch Error as err {
ShowTooltip("Error checking for updates: " err.Message)
return false
}
}
UpdateScript() {
try {
Download("https://github.com/yourusername/Capsulate/releases/latest/download/Capsulate.ahk", A_ScriptDir .
"\Capsulate_new.ahk")
updateScript := '
(
@echo off
timeout /t 1 /nobreak
del "' . A_ScriptFullPath . '"
move "' . A_ScriptDir . '\Capsulate_new.ahk" "' . A_ScriptFullPath . '"
start "" "' . A_ScriptFullPath . '"
del "%~f0"
)'
FileAppend(updateScript, A_ScriptDir . "\update.bat")
Run(A_ScriptDir . "\update.bat", , "Hide")
ExitApp
} catch {
ShowTooltip("Failed to update script.")
}
}
CheckForUpdates(*) {
if (CheckLatestVersion()) {
result := MsgBox("A new version is available. Update now?", "Update Available", "YesNo")
if (result = "Yes") {
UpdateScript()
}
} else {
ShowTooltip("You have the latest version!")
}
}
Jxon_Load(&src, args*) {
key := "", is_key := false
stack := [tree := []]
next := '"{[01234567890-tfn'
pos := 0
while ((ch := SubStr(src, ++pos, 1)) != "") {
if InStr(" `t`n`r", ch)
continue
if !InStr(next, ch, true) {
testArr := StrSplit(SubStr(src, 1, pos), "`n")
ln := testArr.Length
col := pos - InStr(src, "`n", , -(StrLen(src) - pos + 1))
msg := Format("{}: line {} col {} (char {})", (next == "") ? ["Extra data", ch := SubStr(src, pos)][1]
: (next == "'") ? "Unterminated string starting at"
: (next == "\") ? "Invalid \escape"
: (next == ":") ? "Expecting ':' delimiter"
: (next == '"') ? "Expecting object key enclosed in double quotes"
: (next == '"}') ?
"Expecting object key enclosed in double quotes or object closing '}'"
: (next == ",}") ? "Expecting ',' delimiter or object closing '}'"
: (next == ",]") ? "Expecting ',' delimiter or array closing ']'"
: [
"Expecting JSON value(string, number, [true, false, null], object or array)",
ch := SubStr(src, pos, (SubStr(src, pos) ~= "[\]\},\s]|$") - 1)][1]
, ln, col, pos)
throw Error(msg, -1, ch)
}
obj := stack[1]
is_array := (obj is Array)
if i := InStr("{[", ch) { ; start new object / map?
val := (i = 1) ? Map() : Array() ; ahk v2
is_array ? obj.Push(val) : obj[key] := val
stack.InsertAt(1, val)
next := '"' ((is_key := (ch == "{")) ? "}" : "{[]0123456789-tfn")
} else if InStr("}]", ch) {
stack.RemoveAt(1)
next := (stack[1] == tree) ? "" : (stack[1] is Array) ? ",]" : ",}"
} else if InStr(",:", ch) {
is_key := (!is_array && ch == ",")
next := is_key ? '"' : '"{[0123456789-tfn'
} else { ; string | number | true | false | null
if (ch == '"') { ; string
i := pos
while i := InStr(src, '"', , i + 1) {
val := StrReplace(SubStr(src, pos + 1, i - pos - 1), "\\", "\u005C")
if (SubStr(val, -1) != "\")
break
}
if !i ? (pos--, next := "'") : 0
continue
pos := i ; update pos
val := StrReplace(val, "\/", "/")
val := StrReplace(val, '\"', '"')
val := StrReplace(val, "\b", "`b")
val := StrReplace(val, "\f", "`f")
val := StrReplace(val, "\n", "`n")
val := StrReplace(val, "\r", "`r")
val := StrReplace(val, "\t", "`t")
i := 0
while i := InStr(val, "\", , i + 1) {
if (SubStr(val, i + 1, 1) != "u") ? (pos -= StrLen(SubStr(val, i)), next := "\") : 0
continue 2
xxxx := Abs("0x" . SubStr(val, i + 2, 4)) ; \uXXXX - JSON unicode escape sequence
if (xxxx < 0x100)
val := SubStr(val, 1, i - 1) . Chr(xxxx) . SubStr(val, i + 6)
}
if is_key {
key := val, next := ":"
continue
}
} else { ; number | true | false | null
val := SubStr(src, pos, i := RegExMatch(src, "[\]\},\s]|$", , pos) - pos)
if IsInteger(val)
val += 0
else if IsFloat(val)
val += 0
else if (val == "true" || val == "false")
val := (val == "true")
else if (val == "null")
val := ""
else if is_key {
pos--, next := "#"
continue
}
pos += i - 1
}
is_array ? obj.Push(val) : obj[key] := val
next := obj == tree ? "" : is_array ? ",]" : ",}"
}
}
return tree[1]
}
Jxon_Dump(obj, indent := "", lvl := 1) {
if IsObject(obj) {
if !(obj is Array || obj is Map || obj is String || obj is Number)
throw Error("Object type not supported.", -1, Format("<Object at 0x{:p}>", ObjPtr(obj)))
if IsInteger(indent) {
if (indent < 0)
throw Error("Indent parameter must be a postive integer.", -1, indent)
spaces := indent, indent := ""
loop spaces
indent .= " "
}
indt := ""
loop indent ? lvl : 0
indt .= indent
is_array := (obj is Array)
lvl += 1, out := ""
for k, v in obj {
if IsObject(k) || (k == "")
throw Error("Invalid object key.", -1, k ? Format("<Object at 0x{:p}>", ObjPtr(obj)) : "<blank>")
if !is_array ;// key ; ObjGetCapacity([k], 1)
out .= (ObjGetCapacity([k]) ? Jxon_Dump(k) : escape_str(k)) (indent ? ": " : ":") ; token + padding
out .= Jxon_Dump(v, indent, lvl) ; value
. (indent ? ",`n" . indt : ",") ; token + indent
}
if (out != "") {
out := Trim(out, ",`n" . indent)
if (indent != "")
out := "`n" . indt . out . "`n" . SubStr(indt, StrLen(indent) + 1)
}
return is_array ? "[" . out . "]" : "{" . out . "}"
} else if (obj is Number)
return obj
else ; String
return escape_str(obj)
escape_str(obj) {
obj := StrReplace(obj, "\", "\\")
obj := StrReplace(obj, "`t", "\t")
obj := StrReplace(obj, "`r", "\r")
obj := StrReplace(obj, "`n", "\n")
obj := StrReplace(obj, "`b", "\b")
obj := StrReplace(obj, "`f", "\f")
obj := StrReplace(obj, "/", "\/")
obj := StrReplace(obj, '"', '\"')
return '"' obj '"'
}
}