Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Cleaning up swear words

From: btiffin:rogers at: 7-Jul-2007 3:32

Gentle listers, I've got some code to replace swears with comic book #$% stlye strings. Before I post it to rebol.org I thought maybe a few pros could check it over and kick me around a little bit. I'm still pretty new to parse, and this is my first ever charset. So any 'word' experts or parse gurus got any hints or advice? Happy lucky 070707 by the way... Cheers, Brian REBOL [ Title: "Momify bad words" Author: "Brian Tiffin" Date: 06-Jul-2007 File: %momify.r Purpose: "Translate bad words to cartoon speak" Version: 0.9.0 Comment: {Usage: do %momify.r clean "..."} ] ;; protect the global name space ;; do it an object or use global: do %momify context [ ;; It's a fairly incomplete list of bad words. 244 entries. ;; found at http://www.mattfacer.com/swear-filter/ ;; If you want to add to the list: ;; evaluate unhidelist, make your edits, evaluate hidelist, ;; cut'n' paste badwords.bin to badwords ;; then delete badwords.bin and badwords.raw ;; or for more protection use shred -zu on at least badwords.raw file unhidelist: does [ if any [not exists? %badwords.raw confirm "Overwrite badwords? "] [ write/lines %badwords.raw mold to string! first badwords foreach word next badwords [ write/lines/append %badwords.raw mold to string! word ] ] print "cover your eyes and edit %badwords.raw" ] ;; hidelist creates a list of words in binary so if REBOL ;; errors out no one will be exposed to the bad words. ;; After executing hidelist, you'll need to cut'n'paste include the ;; badwords.bin in the badwords definition hidelist: has [base words] [ base: system/options/binary-base system/options/binary-base: 64 words: load %badwords.raw while [not tail? words] [ change words to binary! first words words: next words ] save %badwords.bin compress mold head words system/options/binary-base: base print "Now cut'n'paste %badwords.bin to badwords: in source code" ] badwords: load decompress 64#{ eJx9l9tuqzgUhu/nKUaaFwDTVOWiFztqgaQNUqNdCB7NBYatuAmmKM2JjObd9zIB r2VSzUUkf7/Py+tA/r6/++vfOJq5/O3x8b8/O0rX5/IHkmyQsp/vbt9KJ1KgvqIr ZKt5W7B3pAvtiy/Yek25m7F9VaxpP6+TTc6S1lJ2OXsmY/LQ/7JXL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l9AREP+ov0sbgULHELeUBd7cjEP QU2VLydKmEGBzpSkpLsAsZLkv15pxK2iClQqiEbyBQ9KQ/enGfwbCpfUwp3ybtGQ I3uaUOLueC7NoZ0SLa0bnV26v2vRRGL+LLypzMwtyqfAgV8Vv1lKWFXoS3C2Cv1c 06816YNMVm2y9DRS8H8OkGNXc60UFuFpO4L9yYl6xfb+QR2tE12/ayzFg3+CVGHB gZwlKujuUSlHZFm+U6LhXxCQK2rSB0Rfpdw8O9yby4GCulBDLitVJUnf5ccJY06f EP13dF5NaAVNJh71/8vM5A9N+AUA3xfwr9Gyl1b0f78//vkN4gHQ8mQPAAA} ;; Generate a parse rule rules: copy [] terms: exclude charset [#"^(00)" - #"^(ff)"] charset [#"a" - #"z" #"A" - #"Z" #"0" - #"9"] comicbook: "!-#$%^&*.~*&^%$#-!.~!-#$%^&*.~*&^%$#-!" foreach word badwords [ insert tail rules compose [ mark: (word) [terms | end] (to paren! compose [ change mark copy/part random comicbook (length? word) ]) | ] ] insert tail rules [skip] ;; ;; Get rid of badwords ;; momify: func [ "Replace bad words with comic book text" instr [string!] "String to clean - Modified" ][ parse/all instr [some rules] instr ] ;; uncomment to expose momify as clean, ;; or comment to hide all the words and then the usage is ;; a: do %momify.r a/momify "..." set 'clean :momify ]