Yet another implementation that dodoes not reliesrely on external programs, in bash or kshbash, zsh, yash and some implementations/versions of ksh:
while IFS= read -r line; do
line="${line//[^\"][!\"]/}"
echo $"${#line}"
done <input-file
Use line="${line//[^[!(]}"for counting (.