The functions consider two buffer types, char* (1 byte elements) and short* (2 byte elements). There are three functions for each buffer type, they are find, count and write. Short summary,
- find(), finds the first occurance of a needle in a haystack.
- count(), counts the number of occurances of a needle in a haystack.
- write(), finds position p of a needle in a haystack, and writes a buffer into the haystack at position p + an optional offset.
Documentation
Documentation is available at the github wiki.
Download
Source available at github buf.ahk. (Repo. includes the c source files.)
Example
String count function, counts the line breaks in a string, example for v2
Code: Select all
#include buf.ahk
strCount(byref hay, byref ned, overlap:=0){ ; the corresponding ANSI function would use buf_byte_find instead.
return buf_short_count(&hay, &ned, strlen(hay), strlen(ned), overlap)
}
; Test script:
nLines:=1000000
str:=makeStringWithManyLines(nLines)
t1:=QPC()
nFound:=strCount(str, "`n") ; Count line breaks
t2:=QPC()
msgbox("time taken: " round(t2-t1,3) " ms.`nFound: " nFound " linebreaks.") ; Show result
makeStringWithManyLines(N:=1000000){
static lineText:="some text "
varsetcapacity(str,(N*(strlen(lineText)+strlen(N)))*2)
loop N
str.= lineText A_Index "`n"
return str
}
;-------------------------------------------------------------------------------
QPC() { ; microseconds precision, borrowed from wolf_II
;-------------------------------------------------------------------------------
static Freq, init := DllCall("QueryPerformanceFrequency", "Int64P", Freq)
DllCall("QueryPerformanceCounter", "Int64P", Count)
Return (Count / Freq)*1000
}
v1
Known issuesVery limited testing.
Misc
Feel free to use this in whichever modified or non-modified state you wish, for any peaceful purpose. No credits or references needed.
Have fun and good luck