Takes a mixed variable, formats it for display on the screen, and returns
it.

@param mixed $Mixed An object, array, or string to be formatted.
@return string
542284
public static function Display($Mixed) {
      if (!is_string($Mixed))
         return self::To($Mixed, 'Display');
      else {
         $Mixed = htmlspecialchars($Mixed, ENT_QUOTES, C('Garden.Charset', ''));
         $Mixed = str_replace(array("&quot;","&amp;"), array('"','&'), $Mixed);
         $Mixed = self::Mentions($Mixed);
         $Mixed = self::Links($Mixed);
         
         return $Mixed;
      }
   }
1079366
private function _parse_variable_to()
    {
        $parts = explode('#', $this->_to);
        empty($parts[1]) && $parts[1] = 'index';
        
        $part = is_int(strpos($parts[0], ':')) ? $parts[0] : $parts[1];
        
        preg_match('/:(\w+)/', $part, $m);
        $type = $m[1];
        
        return $type;
    }
784771
public function renderVariable($val, $caller)
    {
        $output = '<pre style="background-color:#ccc;padding:5px;font-size:14px;line-height:18px;">';
        $output .= "<span style=\"font-size: 12px;color:#666;\">" . $this->formatCaller($caller) . " - </span>\n";
        if (is_string($val)) {
            $output .= wordwrap($val, self::config()->columns);
        } else {
            $output .= var_export($val, true);
        }
        $output .= '</pre>';

        return $output;
    }
1276769
public static function convertToEncoding($mixed)
    {
        if (is_null(self::$_encoding)
            || is_numeric($mixed)
            || is_bool($mixed)
            || is_object($mixed)
            || is_array($mixed)
            || !is_string($mixed)
            || !function_exists('mb_convert_encoding')
        ) {
            return $mixed;  
        }
        return \mb_convert_encoding($mixed, self::$_encoding);
    }
536898
public function transform($mixed, array $params = array())
    {
        $facade = $this->newFacade();

        foreach ($mixed as $log) {
            $facade->addLog($this->getContext()->transform('log', $log));
        }

        return $facade;
    }
872904
public function formatValue($value)
    {
        $formatter = $this->getValueFormatter();
        return (string)($formatter ? call_user_func($formatter, $value, $this->getGrid()->getCurrentRow()) : $value);
    }
981966
private function getHash($mixed)
    {
        if ($mixed instanceof File) {
            $mixed = pathinfo($mixed->getHashName(), PATHINFO_EXTENSION);
        }

        return Uuid::uuid4()->toString().'.'.$mixed;
    }
107457
private function getVariableType(string $type): string
    {
        if (!$this->isSimpleType($type)) {
            $type = '\DataProvider\\' . $type . 'DataProvider';
        }

        if ($type === 'DataProviderInterface') {
            $type = '\\' . DataProviderInterface::class;
        }

        if ($type === 'DataProviderInterface[]') {
            $type = '\\' . DataProviderInterface::class . '[]';
        }

        if (strpos($type, '[]') !== false) {
            $type = str_replace('[]', '', $type) . '[]';
        }

        return $type;
    }
327024
public function sqlValue($mixed)
    {
        if(is_object($mixed) && method_exists($mixed, 'toSql')) {
            return $mixed->toSql($this);
        }

        return $this->quote($this->escape($mixed));
    }
463385
protected function formatType($type)
    {
        if (preg_match('/^(?:(.*)\.)?_(.*)$/', $type, $matches)) {
            if ($matches[1] !== '') {
                return sprintf("%s.%s[]", $matches[1], $matches[2]);
            } else {
                return $matches[2].'[]';
            }
        } else {
            return $type;
        }
    }
293621
public function format($type = null)
    {
        $type = $type ?: Constants::DEFAULT_FORMAT;

        if (!is_null($value = $this->config->get("format.{$type}"))) {
            return $this->replaceVariables($value);
        }
    }
886254
private function getClass($mixed = null)
        {
            if (is_object($mixed)) {
                return get_class($mixed);
            }

            if (!is_null($mixed)) {
                return $mixed;
            }

            return $this->getCalledClass();
        }
814711
public function debugVariableText($val)
    {
        // Check debug
        if (is_object($val) && ClassInfo::hasMethod($val, 'debug')) {
            return $val->debug();
        }

        // Format as array
        if (is_array($val)) {
            $result = '';
            foreach ($val as $key => $valItem) {
                $valText = $this->debugVariableText($valItem);
                $result .= "$key = $valText\n";
            }
            return $result;
        }

        // Format object
        if (is_object($val)) {
            return print_r($val, true);
        }

        // Format bool
        if (is_bool($val)) {
            return '(bool) ' . ($val ? 'true' : 'false');
        }

        // Format text
        if (is_string($val)) {
            return wordwrap($val, self::config()->columns);
        }

        // Other
        return var_export($val, true);
    }
146531
private function _printVar($var)
    {
        if (is_string($var)) {
            $search = array("\x00", "\x0a", "\x0d", "\x1a", "\x09");
            $replace = array('\0', '\n', '\r', '\Z', '\t');

            return ('"'.str_replace($search, $replace, $var).'"');
        } elseif (is_bool($var)) {
            if ($var) {
                return ('true');
            } else {
                return ('false');
            }
        } elseif (is_array($var)) {
            $strResult = 'array( ';
            $strComma = '';
            foreach ($var as $key=>$val) {
                $strResult .= $strComma.$this->_printVar($key).' => '.$this->_printVar($val);
                $strComma = ', ';
            }
            $strResult .= ' )';

            return ($strResult);
        }
        // anything else, just let php try to print it
        return (var_export($var, true));
    }
882344
protected function formatValue($value)
    {
        $formatted_value = '<unknown parameter type>';

        if (is_object($value)) {
            $formatted_value = '<' . get_class($value) . ' object>';
        } elseif ($value === null) {
            $formatted_value = '<null>';
        } elseif (is_string($value)) {
            if (SwatString::validateUtf8($value)) {
                $formatted_value = "'" . $value . "'";
            } else {
                $formatted_value = '"' . SwatString::escapeBinary($value) . '"';
            }
        } elseif (is_int($value) || is_float($value)) {
            $formatted_value = strval($value);
        } elseif (is_bool($value)) {
            $formatted_value = $value ? 'true' : 'false';
        } elseif (is_resource($value)) {
            $formatted_value = '<resource>';
        } elseif (is_array($value)) {
            // check whether or not array is associative
            $keys = array_keys($value);
            $associative = false;
            $count = 0;
            foreach ($keys as $key) {
                if ($key !== $count) {
                    $associative = true;
                    break;
                }
                $count++;
            }

            $formatted_value = 'array(';

            $count = 0;
            foreach ($value as $key => $the_value) {
                if ($count > 0) {
                    $formatted_value .= ', ';
                }

                if ($associative) {
                    $formatted_value .= $this->formatValue($key);
                    $formatted_value .= ' => ';
                }
                $formatted_value .= $this->formatValue($the_value);
                $count++;
            }
            $formatted_value .= ')';
        }

        return $formatted_value;
    }
1341901
public static function Markdown($Mixed) {
      if (!is_string($Mixed)) {
         return self::To($Mixed, 'Markdown');
      } else {         
         $Formatter = Gdn::Factory('HtmlFormatter');
         if (is_null($Formatter)) {
            return Gdn_Format::Display($Mixed);
         } else {
            require_once(PATH_LIBRARY.'/vendors/markdown/markdown.php');
            $Mixed = Markdown($Mixed);
            $Mixed = $Formatter->Format($Mixed);
            $Mixed = Gdn_Format::Links($Mixed);
            $Mixed = Gdn_Format::Mentions($Mixed);
            return $Mixed;
         }
      }
   }
609597
protected static function toBin($raw)
	{
		$bin = '';
		foreach (str_split($raw, 1) as $char)
		{
			$bin .= strrev(substr('0000000' . decbin(ord($char)), -8));
		}

		return $bin;
	}