Export a literal as an XPath expression

@param  mixed  $value Literal, e.g. "foo"
@return string        XPath expression, e.g. "'foo'"
446
public static function export($value)
	{
		if (!is_scalar($value))
		{
			throw new InvalidArgumentException(__METHOD__ . '() cannot export non-scalar values');
		}
		if (is_int($value))
		{
			return (string) $value;
		}
		if (is_float($value))
		{
			// Avoid locale issues by using sprintf()
			return preg_replace('(\\.?0+$)', '', sprintf('%F', $value));
		}

		return self::exportString((string) $value);
	}
1272434
public function asNtext($value)
    {
        if ($value === null) {
            return $this->getNullDisplay();
        }

        return nl2br(Html::encode($value));
    }
323495
public function displayValue( $value )
    {
        if ( empty( $value ) )
        {
            return '';
        }

        return $this->view
                    ->htmlTag( 'img', null, array(
                        'data-js-type' => 'js.ui.toolTip',
                        'src'   => $this->view
                                        ->thumbnail( $value,
                                                     $this->getOptions() ),
                        'title' => $this->view
                                        ->htmlTag( 'img', null, array(
                                            'src'   => $value,
                                            'style' => 'max-width: 300px;'
                                                    . ' max-height: 500px;'
                                                    . ' margin-bottom: -3px;',
                                        ) ),
                    ) );
    }
410153
protected function wrapJsonSelector($value)
    {
        $path = explode('->', $value);

        $field = $this->wrapValue(array_shift($path));

        $wrappedPath = $this->wrapJsonPathAttributes($path);

        $attribute = array_pop($wrappedPath);

        if (!empty($wrappedPath)) {
            return $field . '->' . implode('->', $wrappedPath) . '->>' . $attribute;
        }

        return $field . '->>' . $attribute;
    }
1119176
public static function stripInvalidXMLCharacters($value)
    {
        if (Lang::isUnicodeCompiled()) {
            return preg_replace('/[^\x{0009}\x{000a}\x{000d}\x{0020}-\x{D7FF}\x{E000}-\x{FFFD}]+/u', ' ', $value);
        } else {
            $ret = '';

            if (empty($value)) {
                return $ret;
            }

            $length = strlen($value);

            for ($i=0; $i < $length; $i++) {
                $current = ord($value{$i});
                if (($current == 0x9) ||
                    ($current == 0xA) ||
                    ($current == 0xD) ||
                    (($current >= 0x20) && ($current <= 0xD7FF)) ||
                    (($current >= 0xE000) && ($current <= 0xFFFD)) ||
                    (($current >= 0x10000) && ($current <= 0x10FFFF))) {
                    $ret .= chr($current);
                }
            }

            return $ret;
        }
    }
215077
protected function wrapValue($value)
    {
        if ($value === '*') {
            return $value;
        }

        // If the given value is a JSON selector we will wrap it differently than a
        // traditional value. We will need to split this path and wrap each part
        // wrapped, etc. Otherwise, we will simply wrap the value as a string.
        if ($this->isJsonSelector($value)) {
            return $this->wrapJsonSelector($value);
        }

        return '`' . str_replace('`', '``', $value) . '`';
    }
546507
public function scriptLink($value = 0)
    {
        $value = ($value !== 0) ? '\''.urlencode(htmlspecialchars($value)).'\'' : $value;

        return $this->set('href', 'javascript:void('.$value.');');
    }
705567
public function asNtext1line($value, $maxlen = null)
    {
        if ($value === null) {
            return $this->nullDisplay;
        }
        $suffix = '';
        if ((false !== ($n = strpos($value, "\n"))) || (false !== ($n = strpos($value, "\r")))) {
        	if (($n > 0) && (substr($value, $n - 1, 1) == "\r")) {
        		$n--;
        	}
        	$value = substr($value, 0, $n - 1);
        	$suffix = ' ...';	 
        }
        if ($maxlen) {
        	if ((strlen($value) + strlen($suffix) > $maxlen)) {
				$suffix = ' ...';
				$value = substr($value, 0, $maxlen - strlen($suffix));        		
        	}
        }
        return Html::encode($value . $suffix);
    }
868734
private static function encodeHtmlAttributeString($value) {
        if ($value === null) {
            return '';
        }

        $result = $value;

        $result = str_replace('&', '&amp;', $result);
        $result = str_replace('<', '&lt;', $result);
        $result = str_replace('"', '&quot;', $result);
        $result = str_replace('\'', '&#39;', $result);

        return $result;
    }
678981
public function selectLink($value)
    {
        $xpath = sprintf('descendant-or-self::a[contains(concat(\' \', normalize-space(string(.)), \' \'), %s) ', static::xpathLiteral(' '.$value.' ')).
                            sprintf('or ./img[contains(concat(\' \', normalize-space(string(@alt)), \' \'), %s)]]', static::xpathLiteral(' '.$value.' '));

        return $this->filterRelativeXPath($xpath);
    }
396352
static public function formatPath($value)
    {
        $value = preg_replace('/\s+/u', '_', $value);
        $value = preg_replace('/[^a-z0-9\.\:\-\_\s\/\\\\\x{4e00}-\x{9fa5}]/iu', '', $value);
        $value = preg_replace('/\/{2,}/', '/', $value);
        $value = preg_replace('/(\.\/?){2,}/', '', $value);
        return $value;
    }
901614
protected function parseValue($value) {
        if(is_string($value)) {
            $value =  strpos($value,':') === 0 && in_array($value,array_keys($this->bind))? $this->escapeString($value) : '\''.$this->escapeString($value).'\'';
        }
        elseif(isset($value[0]) && is_string($value[0]) && strtolower($value[0]) == 'exp'){
            $value =  $this->escapeString($value[1]);
        }
        elseif(is_array($value)) {
            $value =  array_map([$this, 'parseValue'],$value);
        }
        elseif(is_bool($value)){
            $value =  $value ? '1' : '0';
        }
        elseif(is_null($value)){
            $value =  'null';
        }
        return $value;
    }
702088
protected function scalarValue($value)
    {
        if (is_array($value)) {
            $data = array();
            foreach ($value as $key => $childValue) {
                $data[$key] = $this->scalarValue($childValue);
            }

            return $data;
        } else if (is_object($value)) {
            if (method_exists($value, 'toString')) {
                $value = $value->toString();
            } else if (method_exists($value, '__toString')) {
                $value = (string) $value;
            } else {
                $value = spl_object_hash($value);
            }
        }

        return html_entity_decode($value, ENT_NOQUOTES | ENT_HTML5);
    }
518085
public function asCode($value)
    {
        if ($value instanceof JS) {
            $value = (string) $value;
        } elseif (is_bool($value)) {
            $value = $value ? 'true' : 'false';
        } elseif (is_string($value)) {
            $value = '\''.$value.'\'';
        } elseif (is_array($value)) {
            $tmp = array();
            $useKey = !$this->isKeysNumeric($value);
            foreach ($value as $k => $v) {
                // skip null value
                if (null === $v) {
                    continue;
                }
                $v = $this->asCode($v);
                $tmp[] = $useKey ? sprintf('%s: %s', $k, $v) : $v;
            }
            $multiline = $this->getOption('multiline');
            $value = ($multiline ? "\n" : '').implode($multiline ? ",\n" : ', ', $tmp).($multiline ? "\n" : '');
            if ($useKey) {
                $value = sprintf('{%s}', $value);
            } else {
                $value = sprintf('[%s]', $value);
            }
            if ($multiline) {
                $value = $this->wrapLines($value, 1);
            }
        }

        return $value;
    }
1185140
protected static function convertAttribute($name, $value)
    {
        $isSimpleSelector = !in_array(substr($name, 0, 1), ['^', '!'], true);
        $isSimpleSelector = $isSimpleSelector && (!in_array(substr($name, -1), ['^', '$', '*', '!', '~'], true));

        if ($isSimpleSelector) {
            // if specified only the attribute name
            $xpath = $value === null ? '@'.$name : sprintf('@%s="%s"', $name, $value);

            return $xpath;
        }

        // if the attribute name starts with ^
        // example: *[^data-]
        if (substr($name, 0, 1) === '^') {
            $xpath = sprintf('@*[starts-with(name(), "%s")]', substr($name, 1));

            return $value === null ? $xpath : sprintf('%s="%s"', $xpath, $value);
        }

        // if the attribute name starts with !
        // example: input[!disabled]
        if (substr($name, 0, 1) === '!') {
            $xpath = sprintf('not(@%s)', substr($name, 1));

            return $xpath;
        }

        $symbol = substr($name, -1);
        $name = substr($name, 0, -1);

        switch ($symbol) {
            case '^':
                $xpath = sprintf('starts-with(@%s, "%s")', $name, $value);
                break;
            case '$':
                $xpath = sprintf('substring(@%s, string-length(@%s) - string-length("%s") + 1) = "%s"', $name, $name, $value, $value);
                break;
            case '*':
                $xpath = sprintf('contains(@%s, "%s")', $name, $value);
                break;
            case '!':
                $xpath = sprintf('not(@%s="%s")', $name, $value);
                break;
            case '~':
                $xpath = sprintf('contains(concat(" ", normalize-space(@%s), " "), " %s ")', $name, $value);
                break;
        }

        return $xpath;
    }
787464
public static function phpToXml($value)
    {
        switch (true) {
            case null === $value:
                return 'null';
            case true === $value:
                return 'true';
            case false === $value:
                return 'false';
            case $value instanceof Parameter:
                return '%'.$value.'%';
            case is_object($value) || is_resource($value):
                throw new RuntimeException('Unable to dump a service container if a parameter is an object or a resource.');
            default:
                return (string) $value;
        }
    }
1139999
public function getTransformedValue($value)
    {
        if(is_scalar($value) || (is_object($value) && method_exists($value, '__toString'))) {
            foreach($this->regex as $regex => $replace) {

                if(preg_match($regex, (string)$value))
                    return preg_replace($regex, $replace, $value);
            }
        }

       return $value;
    }