Converts basic concatenations

@param string $value the value to convert

@static
@return string
359836
public static function convertFromConcatenated($value)
    {
        //normalize remaining backslashes
        if ($value != preg_replace('/(\w)\\\/', "$1", $value)) {
            $value .= preg_replace('/(\w)\\\/', "$1", $value);
        }

        $compare = stripslashes($value);

        $pattern = array(
            '/(?:<\/\w+>\+<\w+>)/s',
            '/(?:":\d+[^"[]+")/s',
            '/(?:"?"\+\w+\+")/s',
            '/(?:"\s*;[^"]+")|(?:";[^"]+:\s*")/s',
            '/(?:"\s*(?:;|\+).{8,18}:\s*")/s',
            '/(?:";\w+=)|(?:!""&&")|(?:~)/s',
            '/(?:"?"\+""?\+?"?)|(?:;\w+=")|(?:"[|&]{2,})/s',
            '/(?:"\s*\W+")/s',
            '/(?:";\w\s*\+=\s*\w?\s*")/s',
            '/(?:"[|&;]+\s*[^|&\n]*[|&]+\s*"?)/s',
            '/(?:";\s*\w+\W+\w*\s*[|&]*")/s',
            '/(?:"\s*"\s*\.)/s',
            '/(?:\s*new\s+\w+\s*[+",])/',
            '/(?:(?:^|\s+)(?:do|else)\s+)/',
            '/(?:[{(]\s*new\s+\w+\s*[)}])/',
            '/(?:(this|self)\.)/',
            '/(?:undefined)/',
            '/(?:in\s+)/'
        );

        // strip out concatenations
        $converted = preg_replace($pattern, null, $compare);

        //strip object traversal
        $converted = preg_replace('/\w(\.\w\()/', "$1", $converted);

        // normalize obfuscated method calls
        $converted = preg_replace('/\)\s*\+/', ")", $converted);

        //convert JS special numbers
        $converted = preg_replace(
            '/(?:\(*[.\d]e[+-]*[^a-z\W]+\)*)|(?:NaN|Infinity)\W/ims',
            1,
            $converted
        );

        if ($converted && ($compare != $converted)) {
            $value .= "\n" . $converted;
        }

        return $value;
    }
1102962
public function concatenate($values, $separator = null)
  {
    if ( $separator ){
      return 'CONCATENATE(' . implode(' || ' . $this->q($separator) . ' || ', $values) . ')';
    }
    else {
      return 'CONCATENATE(' . implode(' || ', $values) . ')';
    }
  }
292283
public static function fromString($value)
    {
        $parts = array_filter(array_map('trim', explode(';', $value)));

        if (empty($parts) || !strpos($parts[0], '=')) {
            return [];
        }
        $config = [];

        $pieces = explode('=', array_shift($parts), 2);

        if (count($pieces) !== 2) {
            return [];
        }
        $config['name'] = trim($pieces[0]);
        $config['value'] = urldecode(trim($pieces[1], " \n\r\t\0\x0B"));

        foreach ($parts as $item) {
            $pieces = explode('=', trim($item), 2);
            $pieces[0] = strtolower($pieces[0]);
            if (count($pieces) !== 2) {
                $config[$pieces[0]] = true;
            } else {
                $config[$pieces[0]] = $pieces[1];
            }
        }
        return new static($config);
    }
898484
public static function convertString($value)
    {
        if (strpos($value, '\\') === false) {
            return substr($value, 1, -1);
        }

        if ($value[0] === "'") {
            return strtr(substr($value, 1, -1), ['\\\\' => '\\', '\\\'' => '\'']);
        }

        $value = substr($value, 1, -1);

        return preg_replace_callback(
            '/\\\(n|r|t|v|e|f|\$|"|\\\|x[0-9A-Fa-f]{1,2}|u{[0-9a-f]{1,6}}|[0-7]{1,3})/',
            function ($match) {
                switch ($match[1][0]) {
                    case 'n':
                        return "\n";
                    case 'r':
                        return "\r";
                    case 't':
                        return "\t";
                    case 'v':
                        return "\v";
                    case 'e':
                        return "\e";
                    case 'f':
                        return "\f";
                    case '$':
                        return '$';
                    case '"':
                        return '"';
                    case '\\':
                        return '\\';
                    case 'x':
                        return chr(hexdec(substr($match[0], 1)));
                    case 'u':
                        return self::unicodeChar(hexdec(substr($match[0], 1)));
                    default:
                        return chr(octdec($match[0]));
                }
            },
            $value
        );
    }
1359718
public function convert($value)
    {
        if (!is_scalar($value)) {
            return false;
        }

        if (is_string($value)) {
            return $value;
        }

        if (is_float($value)) {
            return sprintf('float_%.4f', $value);
        }

        $prefix = '';

        if (!is_bool($value)) {
            $prefix = gettype($value) . '_';
        }

        
        return $prefix . var_export($value, true);
    }
872904
public function formatValue($value)
    {
        $formatter = $this->getValueFormatter();
        return (string)($formatter ? call_user_func($formatter, $value, $this->getGrid()->getCurrentRow()) : $value);
    }
536743
public static function VALUE($value = '')
    {
        $value = PHPExcel_Calculation_Functions::flattenSingleValue($value);

        if (!is_numeric($value)) {
            $numberValue = str_replace(
                PHPExcel_Shared_String::getThousandsSeparator(),
                '',
                trim($value, " \t\n\r\0\x0B" . PHPExcel_Shared_String::getCurrencyCode())
            );
            if (is_numeric($numberValue)) {
                return (float) $numberValue;
            }

            $dateSetting = PHPExcel_Calculation_Functions::getReturnDateType();
            PHPExcel_Calculation_Functions::setReturnDateType(PHPExcel_Calculation_Functions::RETURNDATE_EXCEL);

            if (strpos($value, ':') !== false) {
                $timeValue = PHPExcel_Calculation_DateTime::TIMEVALUE($value);
                if ($timeValue !== PHPExcel_Calculation_Functions::VALUE()) {
                    PHPExcel_Calculation_Functions::setReturnDateType($dateSetting);
                    return $timeValue;
                }
            }
            $dateValue = PHPExcel_Calculation_DateTime::DATEVALUE($value);
            if ($dateValue !== PHPExcel_Calculation_Functions::VALUE()) {
                PHPExcel_Calculation_Functions::setReturnDateType($dateSetting);
                return $dateValue;
            }
            PHPExcel_Calculation_Functions::setReturnDateType($dateSetting);

            return PHPExcel_Calculation_Functions::VALUE();
        }
        return (float) $value;
    }
304424
public static function ToString( $value )
	{
		if ( is_string( $value ) )

			return $value;

		if ( is_null( $value ) )

			return "false";

		if ( is_bool( $value ) )

			return $value ? "true" : "false";

		if ( $value instanceof TrueValue )

			return "true";

		if ( $value instanceof FalseValue )

			return "false";

		if ( $value instanceof Integer )

			return $value->ToString( null );

		if ( $value instanceof DecimalValue )

			return $value->getRound( 18 )->ToString( null );

		if ( is_numeric( $value ) && ( is_int( $value ) || $value == PHP_INT_MIN ) ) // PHP does not seem to detect PHP_INT_MIN as an int

			return $value . "";

		if ( is_numeric( $value ) && is_nan( $value ) )
		{
			return "NaN";
		}

		if ( is_numeric( $value ) && is_double( $value ) )
		{
			// Using sprintf( "%e", $value ) is not good enough because it will
			// only produce number with a maximum of 7 significant digits
			/* if( preg_match( "/^(?<sign>-)?(?<zeros>0\.0*)/", $value, $m ) )
			{
				$zeroes = strlen( $m['zeros'] );
				$sign = strlen( $m['sign'] );
				return ( $sign ? "-" : "" ) . substr( $value, $zeroes + $sign, 1 ) . rtrim( "." . substr( $value, $zeroes + $sign + 1 ), "0." ) . "E-" . ( $zeroes-1 );
			}
			else
			 */
			if( preg_match( "/^(?<sign>-)?(?<digits>\d{7,})(?:\.(?<decimals>\d+))?/", $value, $m ) )
			{
				$zeroes = strlen( $m['digits'] );
				$sign = strlen( $m['sign'] );
				$d = rtrim( "." . substr( $m['digits'], 1 ) . ( isset( $m['decimals'] ) ? $m['decimals'] : "" ), "0." );
				if ( empty( $d ) ) $d = ".0";
				$x = ( $sign ? "-" : "" ) . substr( $value, 0 + $sign, 1 ) . $d . "E" . ( $zeroes - 1 );
				return $x;
			}

			return str_replace( "+", "", $value . "" );
		}

		if ( $value instanceof \DateInterval )
		{
			return ( new DurationValue( $value ) )->ToString();
			// return ( new YearMonthDurationValue( $value ) )->ToString();
			// return ( new DayTimeDurationValue( $value ) )->ToString();
		}

		if ( $value instanceof \DateTime )
		{
			$format = "";
			if ( property_exists( $value, "isDate" ) && $value->isDate ) $format .= "Y-m-d";
			if ( property_exists( $value, "isTime" ) && $value->isTime ) $format .= ( empty( $format ) ? "" :"\T" ) . "H:i:s";
			$format .= ( $value->getTimezone()->getName() == date_default_timezone_get() ? "" : "P" );
			return  $value->format( $format ); // DateTimeValue::fromDate( false, $value ) )->ToString();
		}

		return $value->ToString();
	}
884800
private static function convertToString($value): string
    {
        // float value (INF and NAN are float type)
        if (is_float($value)) {
            if (is_infinite($value)) {
                $value = 'INF';
            } elseif (is_nan($value)) {
                $value = 'NAN';
            } else {
                $value = (string) $value;
                if (self::XML_PRESERVE_ZERO_FRACTION && strpos($value, '.') === false) {
                    $value .= '.0';
                }
            }
        }

        // bool value
        if (is_bool($value)) {
            $value = ($value === true) ? 'true' : 'false';
        }

        // class value
        if (is_object($value)) {
            $value = json_encode($value);
        }

        // int or string value.
        return (string) $value;
    }
765776
protected static function prepareNumericCast($value)
    {
        if (!in_array(gettype($value), static::$numericCastable, true)) {
            return '';
        }
        if (is_string($value)) {
            return trim($value);
        }
        return $value;
    }
988389
protected function resolveValue($value) {
    // special treatments, if value is a string
    if (is_string($value)) {
      // replace variables denoted by a leading $
      if (strpos($value, '$') === 0) {
        $value = $this->getInstance(preg_replace('/^\$/', '', $value));
      }
      else {
        // convert booleans
        $lower = strtolower($value);
        if ($lower === 'true') {
          $value = true;
        }
        if ($lower === 'false') {
          $value = false;
        }
      }
    }
    // special treatments, if value is an array
    if (is_array($value)) {
      $result = [];
      $containsInstance = false;
      // check for variables
      foreach ($value as $val) {
        if (is_string($val) && strpos($val, '$') === 0) {
          $result[] = $this->getInstance(preg_replace('/^\$/', '', $val));
          $containsInstance = true;
        }
        else {
          $result[] = $val;
        }
      }
      // only replace value, if the array containes an variable
      if ($containsInstance) {
        $value = $result;
      }
    }
    return $value;
  }
945563
public function typeCast($value)
    {
        if ($value === null) {
            return $value;
        }
        
        switch ($this->type) {
            case 'string':
            case 'text':
            case 'binary':
            default:
                return $value;
            case 'integer':
                return $this->valueToInteger($value);
            case 'float':
                return (float)$value;
            case 'datetime':
            case 'timestamp':
                return $this->stringToTime($value);
            case 'time':
                return $this->stringToDummyTime($value);
            case 'date':
                return $this->valueToDate($value);
            case 'boolean':
                return $this->valueToBoolean($value);
            default:
                return $value;
        }
    }
201235
public static function toString(Value $value)
    {
        if ($value instanceof BooleanValue) {
            return $value->getValue() ? 'true' : 'false';
        } elseif ($value instanceof NumberValue || $value instanceof TextValue) {
            return strval($value->getValue());
        } elseif ($value instanceof DateTimeValue) {
            return $value->getValue() !== null
                ? AdManagerDateTimes::toDateTimeString($value->getValue()) : '';
        } elseif ($value instanceof DateValue) {
            return AdManagerDates::toDateString($value->getValue());
        } elseif ($value instanceof SetValue) {
            $pqlValues = $value->getValues();
            if ($pqlValues !== null) {
                $valuesAsStrings = [];
                foreach ($pqlValues as $pqlValue) {
                    $valuesAsStrings[] = self::toString($pqlValue);
                }

                return implode(',', $valuesAsStrings);
            } else {
                return '';
            }
        } else {
            throw new InvalidArgumentException(
                sprintf('Unsupported value type [%s]', get_class($value))
            );
        }
    }
667713
public function compileString($value)
	{
		foreach ($this->compilers as $compiler)
		{
			$value = $this->{"compile{$compiler}"}($value);
		}

		return $value;
	}
759179
private function prepareValue($value)
    {
        if (is_numeric($value)) {
            return $value;
        }

        if (strpos($value, "\n") !== false) {
            $values = explode("\n", $value);
            foreach ($values as &$line) {
                $line = $this->getIndentation(8) . $line;
            }
            $value = implode("\n", $values);

            return "|\n" . $value;
        }

        return '\'' . str_replace('\'', '\'\'', $value) . '\'';
    }
637695
protected function dumpValue($value): string
    {
        if (null === $value) {
            return 'null';
        }

        if (false === $value) {
            return 'false';
        }
        if (true === $value) {
            return 'true';
        }

        if (\is_int($value) || \is_float($value)) {
            return (string)$value;
        }

        if (\is_string($value)) {
            return StringHelper::dumpString($value);
        }

        throw new \InvalidArgumentException('Unsupported data type:' . gettype($value));
    }
586645
public function appendDouble($value)
    {
        $s = pack("d", $value);
        return $this->append(self::$isLittleEndian ? self::swapEndian64($s) : $s);
    }