/*!
Converts a filter definition and filter data into a text string.
This string is usually the commandline parameter.
438075
static function convertFilterToText( $filterDefinition, $filterData )
    {
        $replaceList = array();
        if ( $filterData['data'] )
        {
            $counter = 1;
            foreach ( $filterData['data'] as $data )
            {
                $replaceList['%' . $counter] = $data;
                ++$counter;
            }
        }
        $argumentText = $filterDefinition['text'];
        $text = eZSys::createShellArgument( $argumentText, $replaceList );
        return $text;
    }
1352897
function filterFile(file, callback) {
      // Ensure it matches the extension.
      const correctExtention = path.extname(file) === opts.extname

      // Make sure it has defined files.
      const source = files[file].source || false
      const destination = files[file].destination || '.'
      callback(null, correctExtention && source && destination)
    }
1092439
function (input) {
    debug('booleanTextFilter(%s)', input);
    var retv = module.exports.booleanFilter(input);
    return (retv === undefined
      ? undefined
      : (retv === false
        ? 'false'
        : 'true'));
  }
1009721
function cleanupFilter(filter) {
  let filterToUse = filter;
  if (
    filterToUse.selectedFilter === "inList" &&
    typeof filterToUse.filterValue === "number"
  ) {
    filterToUse = {
      ...filterToUse,
      filterValue: filterToUse.filterValue.toString()
    };
  }
  if (filterToUse.selectedFilter === "inList") {
    filterToUse = {
      ...filterToUse,
      filterValue: filterToUse.filterValue.replace(/, |,/g, ".")
    };
  }
  return filterToUse;
}
1067968
function runFilter(data, filter) {
  var k, key, keys = Object.keys(filter), keysLength = keys.length;
  var i;

  if (!Object.keys(filter).length) {
    return true;
  }

  keyCheck: for (k = 0; k < keysLength; k++) {
    key = keys[k];

    // Match
    if (key.startsWith('$')) {
      //if (key.startsWith(
      switch (key) {
        case '$or':
          for (i = 0; i < filter[key].length; i++) {
            if (runFilter(data, filter[key][i])) {
              continue keyCheck;
            }
          }
          return false;
        case '$and':
          for (i = 0; i < filter[key].length; i++) {
            if (!runFilter(data, filter[key][i])) {
              return false;
            }
          }
          break;
        case '$not':
          if(runFilter(data, filter[key])) {
            return false;
          }
          break;
      }
    } else if (typeof data === 'object') {
      if (typeof filter[key] === 'object') {
        if (Object.keys(filter[key]).find(function(operator) {
          switch (operator) {
            case '$eq':
              if (data[key] instanceof Array) {
                return data[key].indexOf(filter[key]['$eq']) === -1;
              } else {
                return !data[key] || data[key] !== filter[key]['$eq'];
              }
            case '$ne':
              if (data[key] instanceof Array) {
                return data[key].indexOf(filter[key]['$ne']) !== -1;
              } else {
                return data[key] === filter[key]['$ne'];
              }
            case '$gt':
              return !data[key] || data[key] <= filter[key]['$gt'];
            case '$gte':
              return !data[key] || data[key] < filter[key]['$gte'];
            case '$lt':
              return !data[key] || data[key] >= filter[key]['$lt'];
            case '$lte':
              return !data[key] || data[key] > filter[key]['$lte'];
            case '$in':
              if (!filter[key]['$in'] instanceof Array) {
                throw new Error('$in test values should be an array');
              }

              return filter[key]['$in'].indexOf(data[key]) === -1;
            case '$nin':
              if (!filter[key]['$nin'] instanceof Array) {
                throw new Error('$in test values should be an array');
              }

              return filter[key]['$nin'].indexOf(data[key]) !== -1;
            default:
              throw new Error('Unknown operator ' + operator);
          }
        })) {
          return false;
        }
      } else if (!((data[key] instanceof Array
          && data[key].indexOf(filter[key]) !== -1)
          || data[key] === filter[key])) {
        return false;
      }
    } else {
      return false;
    }
  }

  return true;
  // TODO Handle logical operators
}
1167056
private function input_filter($args) {
		static $magic_quotes_gpc = NULL;
		
		if ($magic_quotes_gpc === NULL)
			$magic_quotes_gpc = (version_compare(PHP_VERSION, '5.4', '<') && get_magic_quotes_gpc());
		
		if (is_array($args)) {
			return array_map(array(& $this, 'input_filter'), $args);
		}
		$res = str_replace("\0", '', $args);
		$magic_quotes_gpc && ($res = stripslashes($res));
		return $res;
	}
1153792
function stringify($fields,$filter=NULL,array $options=NULL) {
		if (!$options)
			$options=[];
		$options+=[
			'group'=>NULL,
			'order'=>NULL,
			'limit'=>0,
			'offset'=>0,
			'comment'=>NULL
		];
		$db=$this->db;
		$sql='SELECT '.$fields.' FROM '.$this->table;
		if (isset($this->as))
			$sql.=' AS '.$this->db->quotekey($this->as);
		$args=[];
		if (is_array($filter)) {
			$args=isset($filter[1]) && is_array($filter[1])?
				$filter[1]:
				array_slice($filter,1,NULL,TRUE);
			$args=is_array($args)?$args:[1=>$args];
			list($filter)=$filter;
		}
		if ($filter)
			$sql.=' WHERE '.$filter;
		if ($options['group']) {
			$sql.=' GROUP BY '.implode(',',array_map(
				function($str) use($db) {
					return preg_replace_callback(
						'/\b(\w+[._\-\w]*)\h*(HAVING.+|$)/i',
						function($parts) use($db) {
							return $db->quotekey($parts[1]).
								(isset($parts[2])?(' '.$parts[2]):'');
						},
						$str
					);
				},
				explode(',',$options['group'])));
		}
		if ($options['order']) {
			$char=substr($db->quotekey(''),0,1);// quoting char
			$order=' ORDER BY '.(is_bool(strpos($options['order'],$char))?
				implode(',',array_map(function($str) use($db) {
					return preg_match('/^\h*(\w+[._\-\w]*)'.
						'(?:\h+((?:ASC|DESC)[\w\h]*))?\h*$/i',
						$str,$parts)?
						($db->quotekey($parts[1]).
						(isset($parts[2])?(' '.$parts[2]):'')):$str;
				},explode(',',$options['order']))):
				$options['order']);
		}
		// SQL Server fixes
		if (preg_match('/mssql|sqlsrv|odbc/', $this->engine) &&
			($options['limit'] || $options['offset'])) {
			// order by pkey when no ordering option was given
			if (!$options['order'])
				foreach ($this->fields as $key=>$field)
					if ($field['pkey']) {
						$order=' ORDER BY '.$db->quotekey($key);
						break;
					}
			$ofs=$options['offset']?(int)$options['offset']:0;
			$lmt=$options['limit']?(int)$options['limit']:0;
			if (strncmp($db->version(),'11',2)>=0) {
				// SQL Server >= 2012
				$sql.=$order.' OFFSET '.$ofs.' ROWS';
				if ($lmt)
					$sql.=' FETCH NEXT '.$lmt.' ROWS ONLY';
			}
			else {
				// SQL Server 2008
				$sql=preg_replace('/SELECT/',
					'SELECT '.
					($lmt>0?'TOP '.($ofs+$lmt):'').' ROW_NUMBER() '.
					'OVER ('.$order.') AS rnum,',$sql.$order,1);
				$sql='SELECT * FROM ('.$sql.') x WHERE rnum > '.($ofs);
			}
		}
		else {
			if (isset($order))
				$sql.=$order;
			if ($options['limit'])
				$sql.=' LIMIT '.(int)$options['limit'];
			if ($options['offset'])
				$sql.=' OFFSET '.(int)$options['offset'];
		}
		if ($options['comment'])
			$sql.="\n".' /* '.$options['comment'].' */';
		return [$sql,$args];
	}
959239
public function filter()
    {

        $command = "grep -n -i -R -E \"" . implode('|', $this->types) . "\"";

        foreach ($this->includePaths as $path) {
            $command .= " $path";
        }

        if ($this->excludePaths) {
            $command .= ' --exclude-dir=' . implode(',', $this->excludePaths);
        }

        exec($command, $commandOutput);

        foreach ($commandOutput as $line) {
            preg_match_all("/(.*):(.*):(.*)/", $line, $pieces, PREG_PATTERN_ORDER);

            foreach ($this->types as $type) {
                if (stristr($pieces[3][0], "@$type")) {

                    // Strip note type text and comment tag
                    $content = preg_replace("/\S+(\s|\s\s+)$type(\s|\s\s+)/", '', $pieces[3][0]);

                    // Strip excess whitespace (space or tab) in beginning string
                    $content = trim(preg_replace('/(\t+|\s\s+)/', '', $content));

                    $this->add(
                        new Line($pieces[1][0], $pieces[2][0], $content, $type)
                    );
                }
            }
        }

        return $this->matches;
    }
28057
private function filter(string $value) : string
    {
        foreach ($this->filters as $filter) {
            $value = $filter($value);
        }

        return $value;
    }
335599
function parseCommandLine(args) {

    var parsed_cmds = [];

    if (args.length <= 2) {
        parsed_cmds.push(defaultCommand());
    } else {

        var cli = args.slice(2);

        var pos = 0;
        var cmd;

        cli.forEach(function(element, index, array) {

            //replace alias name with real name.
            if (element.indexOf('--') === -1 && element.indexOf('-') === 0) {
                cli[index] = alias_map[element];
            }

            //parse command and args
            if (cli[index].indexOf('--') === -1) {
                cmd.args.push(cli[index]);
            } else {

                if (keys[cli[index]] == "undefined") {
                    throw new Error("not support command:" + cli[index]);
                };

                pos = index;
                cmd = commands[cli[index]];
                if (typeof cmd.args == 'undefined') {
                    cmd.args = [];
                };
                parsed_cmds.push(cmd);
            }
        });
    };

    return parsed_cmds;
}
104607
private function scrub($data, $filter = DEFAULT_FILTER, array $options = [])
    {
        //To filter a large array;
        if (is_array($data)) {
            $definedOptions = array_intersect_key($data, $options);
            if (count($data) == count($definedOptions)) {
                return $this->filterArray($data, $options);
            } else {
                $sanitized = [];
                foreach ($data as $key => $variable) {
                    $type = gettype($variable);

                    switch ($type) {
                        case "integer":
                            $sanitized[$key] = $this->int($variable);
                            break;
                        case "float":
                        case "double":
                            $sanitized[$key] = $this->float($variable);
                            break;
                        case "string":
                            $sanitized[$key] = $this->string($variable);
                            break;
                        case "object": //@TODO maybe serialize?,
                        case "resource":
                            //there is not much to be done with objects;
                            //maybe should come up with a way to check how safe they are;
                            $this->sanitized = true;
                            $sanitized[$key] = $variable;
                            break;
                        case "NULL":
                        case "unknown type":
                        default:
                            $sanitized[$key] = $this->filter($variable, static::FILTER_RAW, $options);
                            break;
                    }
                }

                return $sanitized;
            }
        }

        //bitwise disjunction of flags
        $options['flags'] = implode("|", $options['flags']);

        return $this->filter($data, $filter, $options);
    }
1189132
def show(self, filter=None):
        
        for command in self._commands:
            if command[0] is None:  # or command[1] in self._invalid_objects:
                continue  # Skip nill commands
            if filter and command[0] != filter:
                continue
            t = []
            for e in command:
                if isinstance(e, np.ndarray):
                    t.append('array %s' % str(e.shape))
                elif isinstance(e, str):
                    s = e.strip()
                    if len(s) > 20:
                        s = s[:18] + '... %i lines' % (e.count('\n')+1)
                    t.append(s)
                else:
                    t.append(e)
            print(tuple(t))
49634
function computeFilterFn(filter) {
     if (filter) {
        if (typeof filter === 'string') {
           var regex = new RegExp(filter);
           return function(filePath) { return regex.test(filePath); }
        }
        else if (filter instanceof RegExp)
           return function(filePath) { return filter.test(filePath); }
        else   // must be a function itself
           return filter;
      }
      else  // none, return "pass all"
         return function() { return true; };
   }
333828
static function sanitize($data)
	{
		// remove whitespaces (not a must though)
		//$data = filter_var(trim($data), FILTER_SANITIZE_STRING, !FILTER_FLAG_STRIP_LOW);
		$data = trim(strip_tags($data));
		
		// apply stripslashes if magic_quotes_gpc is enabled
		if(get_magic_quotes_gpc())
			$data = stripslashes($data);
			
		// SQL commands are forbidden
		$banlist = array
			(
			"/alter /i", "/insert /i", "/select /i", "/update /i", "/delete /i", "/distinct /i", "/having /i", "/truncate /i", "/replace /i",
			"/handler /i", "/like /i", "/procedure /i", "/limit /i", "/order by /i", "/group by /i" , "/drop /i", "/database /i"
			);
			
		$data = preg_replace($banlist, '', $data);
		
		return $data;
	}
861179
def _filter_string(value):
        
        if value is None:
            value = ""

        # replace whitespace with space
        value = value.replace("\n", " ")
        value = value.replace("\t", " ")

        # CSV seperator
        value = value.replace("|", " ")

        # remove leading/trailing whitespace
        value = value.strip()

        # hack because MAM doesn't quote sql correctly
        value = value.replace("\\", "")

        # Used for stripping non-ascii characters
        value = ''.join(c for c in value if 31 < ord(c) < 127)

        return value
488829
function FilterloadMessage(arg, options) {
  Message.call(this, options);
  this.command = 'filterload';
  $.checkArgument(
    _.isUndefined(arg) || arg instanceof BloomFilter,
    'An instance of BloomFilter or undefined is expected'
  );
  this.filter = arg;
}
132557
public function hookFilter($text, $filter, &$filtered)
    {
        if (!isset($filtered) && (!isset($filter['filter_id']) || $filter['filter_id'] === 'xss')) {
            $filtered = $this->filter($text);
        }
    }