Torque3D Documentation / _generateds / badWordFilter.h

badWordFilter.h

Engine/source/app/badWordFilter.h

More...

Classes:

Public Variables

Detailed Description

Public Variables

BadWordFilter * gBadWordFilter 
 1
 2//-----------------------------------------------------------------------------
 3// Copyright (c) 2012 GarageGames, LLC
 4//
 5// Permission is hereby granted, free of charge, to any person obtaining a copy
 6// of this software and associated documentation files (the "Software"), to
 7// deal in the Software without restriction, including without limitation the
 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 9// sell copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in
13// all copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21// IN THE SOFTWARE.
22//-----------------------------------------------------------------------------
23#ifndef _H_BADWORDFILTER
24#define _H_BADWORDFILTER
25
26#include "core/util/tVector.h"
27
28class BadWordFilter
29{
30private:
31   struct FilterTable
32   {
33      U16 nextState[26]; // only 26 alphabetical chars.
34      FilterTable();
35   };
36   friend struct FilterTable;
37   Vector<FilterTable*> filterTables;
38
39   enum {
40      TerminateNotFound = 0xFFFE,
41      TerminateFound = 0xFFFF,
42      MaxBadwordLength = 32,
43   };
44   char defaultReplaceStr[32];
45
46   BadWordFilter();
47   ~<a href="/coding/class/classbadwordfilter/">BadWordFilter</a>();
48   U32 curOffset;
49   static U8 remapTable[257];
50   static U8 randomJunk[MaxBadwordLength + 1];
51   static bool filteringEnabled;
52
53public:
54   bool addBadWord(const char *word);
55   bool setDefaultReplaceStr(const char *str);
56   const char* getDefaultReplaceStr(){ return defaultReplaceStr; }
57   void filterString(char *string, const char *replaceStr = NULL);
58   bool containsBadWords(const char *string);
59
60   static bool isEnabled() { return filteringEnabled; }
61   static void setEnabled(bool enable) { filteringEnabled = enable; }
62   static void create();
63   static void destroy();
64};
65
66extern BadWordFilter *gBadWordFilter;
67
68#endif
69