function cc.splitStringToWords(str) local words = {} for uchar in string.gfind(str,"[%z-74-4][8-1]*") do words[#words+1] = uchar end return wordsendfunction cc.filterSensitiveWord(str) local filter = { [" "] = true,["。"] = true,[","] = true,["、"] = true,[";"] = true,[":"] = true,["’"] = true,["‘"] = true,["."] = true,[","] = true,["/"] = true,[";"] = true,[":"] = true,["'"] = true,} print("原字符:",str) local words = cc.splitStringToWords(str) local exist = false local pos = 1 while pos <= #words do local tmp = pos local t = cc.csvData["sensitive_words"][words[pos]] while t ~= nil do if next(t) then tmp = tmp +1 if filter[words[tmp]] then tmp = tmp +1 end t = t[words[tmp]] else print("find",pos,tmp) exist = true for i=pos,tmp do if filter[words[i]] ~= true then words[i] = "*" end end break end end if tmp ~= pos then pos = tmp else pos = pos +1 end end local newStr = "" if exist then for i=1,#words do newStr = newStr .. words[i] end else newStr = str end print("过滤后:",newStr) return newStrend
csv = path.."config/sensitive_words.csv" cc.csvData["sensitive_words"] = {} cc.praseCSV(csv,function (IDx,vals) local words = cc.splitStringToWords(vals["code"]) --print("word",vals["code"],#words) local t = cc.csvData["sensitive_words"] local pos = 1 while pos <= #words do if not t[words[pos]] then t[words[pos]] = {} end t = t[words[pos]] pos = pos+1 end end)
单词code习大大总结
以上是内存溢出为你收集整理的cocos2d-lua敏感词过滤函数全部内容,希望文章能够帮你解决cocos2d-lua敏感词过滤函数所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)