• 去除特殊字符


        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;
    }

  • 相关阅读:
    JavaScripts广告轮播图以及定时弹出和定时隐藏广告
    JavaScript正则表达
    表单常用标签 和 属性
    html框架集
    Hbuilder 快捷键
    css 图片
    html input accept类型
    db2 sql
    js 数组排序
    html input size maxlength
  • 原文地址:https://www.cnblogs.com/sharpfeng/p/1951915.html
Copyright © 2020-2023  润新知