Consider this:

1. Create a const, static table of character mappings. It would map the entire 8-bit character range to either itself or '.'

2. On entry, loop over each character in the input string. Pass the input chars through the table.

3. If the table value is '.', then

3a. If TV, then call the add_character function as now.

3b. If no TV, store the dot.

4. If the table value is not '.', just store the result.


This brings two questions to mind. First, what is your policy for "out of range" characters, like all the ASCII values below space? Is it okay to have a filename with newlines or tabs in it? Second, what is the status of dot in filenames? If you have a filename like foo.txt, is the dot going to be added to the SPECIAL characters list? Or is dot already handled before this function is called?