fix compiler warning and optimization

fix compiler warning and optimization

clang++ was warning that adding a char to a string does not append to
the string, so I changed it to std::string.push_back(c);

I also changed the loop into a switch statement, allowing for better
compiler optimization than the loop.