Bug #23715 in COLLADA exporter: prepend an '_' to the ID if it starts with an illegal...
authorArystanbek Dyussenov <arystan.d@gmail.com>
Thu, 9 Sep 2010 11:01:30 +0000 (11:01 +0000)
committerArystanbek Dyussenov <arystan.d@gmail.com>
Thu, 9 Sep 2010 11:01:30 +0000 (11:01 +0000)
Pointed out by Tom Haines. Thanks!

source/blender/collada/DocumentExporter.cpp

index ae00942b89d3e0651c112dd5e3e77744a74080c5..a5b4b1423bff631cfcf03c94dd32a8ed1f241c9a 100644 (file)
@@ -236,8 +236,14 @@ static std::string translate_id(const std::string &id)
        if (id.size() == 0)
        { return id; }
        std::string id_translated = id;
-       id_translated[0] = translate_start_name_map[(unsigned int)id_translated[0]];
-       for (unsigned int i=1; i < id_translated.size(); i++)
+       int offset = 0;
+       // prepend '_' if the first character is illegal and not '_' already
+       if (id[0] != '_' && translate_start_name_map[(unsigned int)id[0]] == '_')
+       {
+               id_translated.insert(0, 1, '_');
+               offset = 1;
+       }
+       for (unsigned int i=offset; i < id_translated.size(); i++)
        {
                id_translated[i] = translate_name_map[(unsigned int)id_translated[i]];
        }