std::string ConvertName(TCHAR const * name)
{
if (name == 0)
{
return std::string(_T("unnamed"));
}
std::string ret(name);
if ((name[0] >= '0') && (name[0] <= '9'))
{
ret = std::string("_") + ret;
}
for (size_t i = 0; i < ret.size(); ++i)
{
TCHAR ch = ret[i];
if (((ch >= '0') && (ch <= '9'))
|| ((ch >= 'A') && (ch <= 'Z'))
|| ((ch >= 'a') && (ch <= 'z')))
{
continue;
}
ret[i] = '_';
}
return ret;
}
char const * SafeName(IGameNode * node, char const *prefix)
{
static char buf[256];
char const * name = node->GetName();
if (!name || !name[0]) {
sprintf(buf, "%s_%lx", prefix, (long)(size_t)node);
return buf;
}
sprintf(buf, "%s_%s", prefix, name);
for (char *ptr = buf; *ptr; ++ptr) {
if ((*ptr > 126) || (*ptr < 33) || (*ptr == '/') || (*ptr == '{') || (*ptr == '}') || (*ptr == '\"' || *ptr == '\'' || *ptr == '#')) {
*ptr = '_';
}
}
return buf;
}