Use getline for function countlinesmatches (makes it dynamic)

Close #3852. Lifts restriction on ExpandAndMapIteratorsFromScalar for CF_BUFSIZE