- I wanted to be able to check if a string was ASCII. If ASCII, save a file without a BOM, else, save a file as UTF-8 with a BOM.
- Loop can be slow, and RegEx can be slow, so it was a battle of two 'slownesses'. RegEx was much faster in these examples.
Code: Select all
q:: ;compare Loop v. RegEx to determine if text is ASCII
oQPC := []
vNum := 1000
vLen := 10000
vText := ""
VarSetCapacity(vText, vLen*2)
;vText .= Chr(8730) ;non-ASCII is first character (square root)
Loop, % vLen-1
vText .= "a"
vText .= Chr(8730) ;non-ASCII is last character (square root)
vQPC := QPC()
Loop, % vNum
{
Loop, Parse, vText
if (Ord(A_LoopField) > 127)
break
}
oQPC.Push(QPC()-vQPC)
vQPC := QPC()
Loop, % vNum
RegExMatch(vText, "[^[:ascii:]]")
oQPC.Push(QPC()-vQPC)
Clipboard .= "`r`n;" oQPC.1 "`t" oQPC.2
MsgBox, % Clipboard
return
;Ord RegExMatch [non-ASCII is first character]
;18.860856 0.866409
;20.594957 0.824927
;17.477852 0.316030
;11.557107 0.514885
;18.875824 0.827921
;Ord RegExMatch [non-ASCII is last character]
;1570.211616 230.783343
;1549.919432 226.551368
;1565.157279 229.756140
;1573.236349 230.733309
;1540.161855 233.202531