- It's also useful to keep leading whitespace consistent, and trailing whitespace non-existent.
Code: Select all
q:: ;files - whitespace summary
;frequency count: leading/trailing spaces/tabs permutations
;vDir1 := A_Desktop "\AutoHotkey_L-master\source"
vDir1 := A_ScriptDir
vDoMsg := 1
vDoMsgL := 0
vDoMsgR := 0
VarSetCapacity(vOutputAll, 1000000*2)
Loop, Files, % vDir1 "\*", F
{
vPath := A_LoopFileFullPath
SplitPath, vPath, vName, vDir, vExt, vNameNoExt, vDrive
FileRead, vText, % vPath
oArrayL := {base:{__Get:Func("Abs").Bind(0)}} ;AHK basic object with default value of 0
oArrayR := {base:{__Get:Func("Abs").Bind(0)}} ;AHK basic object with default value of 0
Loop, Parse, vText, `n, `r
{
vTemp := A_LoopField
vPos1 := RegExMatch(vTemp, "[^ `t]")
vPos2 := RegExMatch(vTemp, "[ `t](?=[ `t]*$)")
vWhitespaceL := SubStr(vTemp, 1, vPos1-1)
vWhitespaceR := vPos2 ? SubStr(vTemp, vPos2) : ""
if vWhitespaceL
oArrayL[vWhitespaceL]++
if vWhitespaceR
oArrayR[vWhitespaceR]++
if vDoMsgL && InStr(vWhitespaceL, " ")
MsgBox, % "[" JEE_StrReplaceST(vWhitespaceL) "][" vTemp "]"
if vDoMsgR && InStr(vWhitespaceR, " ")
MsgBox, % "[" vTemp "][" JEE_StrReplaceST(vWhitespaceR) "]"
}
vOutput := vName "`r`n`r`n" "start:`r`n"
for vKey, vValue in oArrayL
vOutput .= vValue "`t" JEE_StrReplaceST(vKey) "`r`n"
vOutput .= "`r`n" "end:`r`n"
for vKey, vValue in oArrayR
vOutput .= vValue "`t" JEE_StrReplaceST(vKey) "`r`n"
if vDoMsg
MsgBox, % vOutput
vOutputAll .= vOutput "`r`n"
}
Clipboard := vOutputAll
MsgBox, % "done"
return
JEE_StrReplaceST(vText)
{
vText := StrReplace(vText, " ", "S")
return StrReplace(vText, "`t", "T")
}