Home > other > Lua implementation special characters filtering
Lua implementation special characters filtering
Time:09-17
The function filter_spec_chars (s, charTypes) The local ss={} The local k=1 While true do If k & gt; # s then break end The local c=string. Byte (s, k) If not then c break end If cIf (c>=48 and c<=57) then If charTypes. Num then Table. The insert (ss, string. Char (c)) End Elseif (c>=65 and c<=90) or (c>=97 and c<=122) then If charTypes. Char then Table. The insert (ss, string. Char (c)) End End K=k + 1 Elseif cK=k + 2 Elseif cIf c>=228 and cLocal c1=string, byte (s, k + 1) The local c2=string. Byte (s, k + 2) If c1 and c2 then The local a1, a2, a3, a4=128191128191 If c==228 then a1=184 Elseif c==233 then a2, a4=190, c1 ~=190 and 191 or 165 End If c1 & gt;=a1 and c1 & lt;=a2 and c2 & gt;=a3 and c2 & lt;=a4 then If charTypes. CHS then Table. The insert (ss, string. Char (c, c1, c2)) End End End End K=k + 3 Elseif cK=k + 4 Elseif cK=k + 5 Elseif cK=k + 6 End End Return to the table. The concat (ss) End
The local function main () Print (filter_spec_chars (" hello OI + 123) * & amp; ^ # @ 163. com ", {num="number", char="letters", CHS="Chinese"})) End The main ()
CodePudding user response:
You this kind of thing is not practical, several filtering M file will be stuck