00001 // /////////////////////////////////////////////////////////////////////////// 00002 // xrb_characterfilter.cpp by Victor Dods, created 2005/02/23 00003 // /////////////////////////////////////////////////////////////////////////// 00004 // Unless a different license was explicitly granted in writing by the 00005 // copyright holder (Victor Dods), this software is freely distributable under 00006 // the terms of the GNU General Public License, version 2. Any works deriving 00007 // from this work must also be released under the GNU GPL. See the included 00008 // file LICENSE for details. 00009 // /////////////////////////////////////////////////////////////////////////// 00010 00011 #include "xrb_characterfilter.hpp" 00012 00013 namespace Xrb 00014 { 00015 00016 char CharacterFilter::FilteredCharacter (char const c) const 00017 { 00018 char const *filter = Filter().c_str(); 00019 00020 // filter the character according to if the filter 00021 // specifies allowed/disallowed 00022 switch (GetFilterType()) 00023 { 00024 case ALLOW: 00025 // allowed indicates that only characters in the filter 00026 // string should be able to be typed 00027 while (*filter) 00028 { 00029 // if the character was found in the filter, return it 00030 if (c == *filter) 00031 return c; 00032 00033 ++filter; 00034 } 00035 // the character wasn't found in the filter, return null char 00036 return '\0'; 00037 00038 case DENY: 00039 // disallowed indicates that characters in the filter 00040 // string should not be able to be typed 00041 while (*filter) 00042 { 00043 // if the character was found in the filter, return null char 00044 if (c == *filter) 00045 return '\0'; 00046 00047 ++filter; 00048 } 00049 // if the character wasn't filtered out, return it 00050 return c; 00051 00052 default: 00053 ASSERT1(false && "Invalid character filter type"); 00054 return '\0'; 00055 } 00056 } 00057 00058 } // end of namespace Xrb