// because each name must remain unique in the global scene.
if (aNode->Name())
if (* aNode->Name() != '\0') {
- char buf[1024];
- strncpy (buf, aFileName.ToCString(), sizeof(buf));
- char * ptr = strchr (buf, '.');
- if (!ptr)
- ptr = strchr (buf,'\0');
- * ptr = '_';
- strncpy (ptr+1, aNode->Name(), (&buf[sizeof(buf)]-ptr)-2);
- const size_t len = strlen(buf) + 1;
+ TCollection_AsciiString buf;
+ buf += aFileName;
+ Standard_Integer aCharLocation = buf.Location (1, '.', 1, buf.Length());
+ if (aCharLocation != 0)
+ {
+ buf.Remove (aCharLocation, buf.Length() - aCharLocation + 1);
+ }
+ buf += '_';
+ buf += aNode->Name();
+ const size_t len = buf.Length();
char * aNewName =
static_cast<char *> (Scene().Allocator()->Allocate (len));
if (aNewName) {
aNode->myName = aNewName;
- memcpy (aNewName, buf, len);
+ memcpy (aNewName, buf.ToCString(), len);
}
}
}
aStatus = theNode->Write (thePrefix);
else {
// Name is written under DEF clause
- char buf[1024], * ptr;
- if (myNamedNodesOut.Contains (theNode)) {
- memcpy (buf, "USE ", 4);
- strncpy (&buf[4], theNode->Name(), sizeof(buf)-5);
- aStatus = WriteLine (thePrefix, buf);
- } else {
- if (thePrefix) {
- strncpy (buf, thePrefix, sizeof(buf));
- ptr = strchr (buf, '\0');
- * ptr++ = ' ';
- } else
- ptr = &buf[0];
- strcpy (ptr, "DEF ");
- strncpy (ptr+4, theNode->Name(), &buf[sizeof(buf)] - (ptr+5));
- aStatus = theNode->Write (buf);
+ TCollection_AsciiString buf;
+ if (myNamedNodesOut.Contains (theNode))
+ {
+ buf += "USE ";
+ buf += theNode->Name();
+ aStatus = WriteLine (thePrefix, buf.ToCString());
+ }
+ else
+ {
+ if (thePrefix)
+ {
+ buf += thePrefix;
+ buf += ' ';
+ }
+ buf += "DEF ";
+ buf += theNode->Name();
+ aStatus = theNode->Write (buf.ToCString());
const_cast<VrmlData_MapOfNode&>(myNamedNodesOut).Add (theNode);
}
}