Quote field.
@param  string $input
@return string
@throws Oppa\Agent\AgentException
484661
public function quoteField(string $input): string
    {
        $input = $this->unquoteField($input);

        // nope.. quote all
        // if (ctype_lower($input)) {
        //     return $input;
        // }

        if ($this->isMysql()) {
            return '`'. str_replace('`', '``', $input) .'`';
        } elseif ($this->isPgsql()) {
            return '"'. str_replace('"', '""', $input) .'"';
        }
    }
1080856
public function quoteIdentifier($text)
    {
        if ($this->getTable()->isIdentifierQuotingEnabled()) {
            return $this->getPlatform()->doQuoting($text);
        }

        return $text;
    }
907603
public function getEncQuoted($input) {

        if (is_array($input)) {
            foreach ($input as $key=>$content) {
                $input[$key] = $this->getEncQuoted($content);
            }
            return $input;
        } else {
            // Always lowercase
            $input = strtolower($input);
            // if reserved or quote_all or has hyphens, quote it
            if ($this->quote_all || in_array($input, $this->reserved_words) || strpos($input, '-') !== false) {
                $input = $this->quote_string . $input . $this->quote_string;
            }
            return $input;
        }
    }
795061
private static function _prepareQuestionString($input)
    {
        $regex = '';
        if (is_array($input) === true) {
            $regex = '^';
            $start = true;
            foreach ($input as $row) {
                if ($start === false) {
                    $regex .= '|';
                }

                $start  = false;
                $regex .= '(';
                $one    = null;
                if (strlen($row) > 2) {
                    $one = true;
                }

                foreach (str_split($row, 1) as $char) {
                    $regex .= '[' . $char;
                    $regex .= strtoupper($char) . ']';
                    if ($one === true) {
                        $one    = false;
                        $regex .= '(';
                    }
                }

                if ($one === false) {
                    $regex .= ')';
                }

                $regex .= '?)';
            }
        }

        return $regex;
    }
220765
public function dump($input)
    {

        foreach ($this->lex($input) as $token) {

            $type = $token['type'];
            $line = $token['line'];
            $offset = $token['offset'];
            unset($token['type'], $token['line'], $token['offset']);

            echo "[$type($line:$offset)";
            $vals = implode(', ', array_map(function ($key, $value) {

                return "$key=$value";
            }, array_keys($token), $token));

            if (!empty($vals))
                echo " $vals";

            echo ']';

            if ($type === 'newLine')
                echo "\n";
        }
    }
386945
protected function quoteField($field)
    {
        # The odbc sql only uses it's quote strings for renaming fields, not for quoting table/field names
        if ($this->mode == "odbc") {
            return $field;
        }

        $field = trim($field);

        $chars = $this->quoteChars[$this->mode];

        if (is_array($chars)) {
            $from = $chars[0];
            $to = $chars[1];
        } else {
            $from = $chars;
            $to = $chars;
        }

        $quoted = $from . $field . $to;

        return $quoted;
    }
734071
public function quote($text)
    {
        if (false !== ($pos = strrpos($text, '.'))) {
            $table = substr($text, 0, $pos);
            $column = substr($text, $pos + 1);
        } else {
            $table = '';
            $column = $text;
        }

        if ($table) {
            return $this->quoteIdentifierTable($table) . '.' . $this->quoteIdentifier($column);
        } else {
            return $this->quoteIdentifier($column);
        }
    }
522573
protected function _quote($value)
    {
        if (is_int($value)) {
            return $value;
        } elseif (is_float($value)) {
            return sprintf('%F', $value);
        }
        return "'" . addcslashes($value, "\000\n\r\\'\"\032") . "'";
    }
1245427
public static function formatStringToMethodName(string $input) : string
    {
        $methodName = implode('', array_map('ucfirst', explode('_', strtolower($input))));

        return $methodName;
    }
768711
public static function unXSS($input)
    {
        $return = '';
        if (version_compare(phpversion(), '5.4', '<')) {
            $return = htmlspecialchars($input);
        } else {
            $return = htmlentities($input, ENT_QUOTES | ENT_DISALLOWED | static::$outputLanguage);
        }

        return $return;
    }
1160402
public function literal($input, $type = null)
    {
        // TODO remove
        if (!is_string($input)) {
            return $input;
        }
        // TODO remove

        return $this->connection->quote($input, $type);
    }
376062
public function escape($input, string $inputFormat = null, bool $quote = true)
    {
        $inputType = gettype($input);

        // in/not in statements
        if ($inputType == 'array') {
            return join(', ', array_map([$this, 'escape'], $input));
        }

        // escape strings %s and for all formattable types like %d, %f and %F
        if ($inputFormat && $inputFormat[0] == '%') {
            if ($inputFormat == '%s') {
                return $this->escapeString((string) $input, $quote);
            } elseif ($inputFormat == '%sl') {
                return $this->escapeLikeString((string) $input, $quote);
            } elseif ($inputFormat == '%b') {
                if (is_bool($input)) {
                    return $input ? 'TRUE' : 'FALSE';
                }
                throw new AgentException("Boolean types accepted only for %b operator, {$inputType} given!");
            }

            if (is_string($input) && in_array($inputFormat, ['%d', '%i', '%f', '%F'])) {
                $input = $this->unquote($input);
            }

            return sprintf($inputFormat, $input);
        }

        switch ($inputType) {
            case 'NULL':
                return 'NULL';
            case 'string':
                return $this->escapeString($input, $quote);
            case 'integer':
                return $input;
            case 'boolean':
                return $input ? 'TRUE' : 'FALSE';
            case 'double':
                return sprintf('%F', $input); // %F = non-locale aware
            default:
                // no escape raws sql inputs like NOW(), ROUND(total) etc.
                if ($input instanceof Sql) {
                    return $input->toString();
                }

                throw new AgentException("Unimplemented '{$inputType}' type encountered!");
        }

        return $input;
    }
1161645
public final function prepareIdentifier(string $input, $inputParam): string
    {
        if (empty($inputParam)) {
            if (strpos($input, '%n') !== false) {
                throw new AgentException('Found %n operator but no replacement parameter given!');
            } elseif (strpos($input, '??') !== false) {
                throw new AgentException('Found ?? operator but no replacement parameter given!');
            }
        } else {
            $input = $this->prepare($input, (array) $inputParam);

            // eg: ('@a.id=?', 1), ('@a.id=@b.id')
            // eg: ('??=?', ['a.id',1]), ('??=??', ['a.id','b.id'])
            // eg: ('a.id=?, a.b=?', [1,2]), ('a.id=??, a.b=?', ['b.id',2])
            if (strpos($input, '=')) {
                $input = implode(', ', array_map(function ($input) {
                    $input = trim($input);
                    if ($input != '') {
                        $input = array_map('trim', explode('=', $input));
                        $input = $this->escapeIdentifier($input[0]) .' = '. (
                            ($input[1] && $input[1][0] == '@' )
                                ? $this->escapeIdentifier($input[1]) : $input[1]
                        );
                        return $input;
                    }
                }, explode(',', $input)));
            }

            return $input;
        }

        // eg: (a.id = 1), (a.id = @b.id)
        if (strpos($input, '=')) {
            $input = implode(', ', array_map(function ($input) {
                $input = trim($input);
                if ($input != '') {
                    $input = array_map('trim', explode('=', $input));
                    $input = $this->escapeIdentifier($input[0]) .' = '. (
                        ($input[1] && $input[1][0] == '@' )
                            ? $this->escapeIdentifier($input[1]) : $this->escape($input[1])
                    );
                    return $input;
                }
            }, explode(',', $input)));
        } else {
            // eg: a.id
            $input = $this->escapeIdentifier($input);
        }

        return $input;
    }
489175
public function quoteIdentifier($text)
    {
        if (!$this->getPlatform()) {
            throw new RuntimeException('No platform specified. Can not quote without knowing which platform this table\'s database is using.');
        }

        if ($this->isIdentifierQuotingEnabled()) {
            return $this->getPlatform()->doQuoting($text);
        }

        return $text;
    }
1191300
public function quote($text)
    {
        if ($con = $this->getConnection()) {
            return $con->quote($text);
        } else {
            return "'" . $this->disconnectedEscapeText($text) . "'";
        }
    }
997147
public function prepare($input)
    {
        foreach ($input as $key => $record) {
            $this->setFieldOriginalValue($key);
            $input[$key] = $this->prepareValue($key, $record);
        }

        return $input;
    }
793319
protected function filter($input): string
    {
        $input = parent::filter((string)$input);
        return preg_replace('/\s/', '', $input);
    }