It seems a bit dangerous to me to work on a per-character basis here. E.g. if a line contains a few spaces in the end and the name is embraced in ", the code will stop before even reaching the texture name and skip all.