Cleanups a YAML string to be parsed.

@param string $value The input YAML string

@return string A cleaned up YAML string
327106
private function cleanup($value)
    {
        $value = str_replace(array("\r\n", "\r"), "\n", $value);

        // strip YAML header
        $count = 0;
        $value = preg_replace('#^\%YAML[: ][\d\.]+.*\n#u', '', $value, -1, $count);
        $this->offset += $count;

        // remove leading comments
        $trimmedValue = preg_replace('#^(\#.*?\n)+#s', '', $value, -1, $count);
        if (1 == $count) {
            // items have been removed, update the offset
            $this->offset += substr_count($value, "\n") - substr_count($trimmedValue, "\n");
            $value = $trimmedValue;
        }

        // remove start of the document marker (---)
        $trimmedValue = preg_replace('#^\-\-\-.*?\n#s', '', $value, -1, $count);
        if (1 == $count) {
            // items have been removed, update the offset
            $this->offset += substr_count($value, "\n") - substr_count($trimmedValue, "\n");
            $value = $trimmedValue;

            // remove end of the document marker (...)
            $value = preg_replace('#\.\.\.\s*$#', '', $value);
        }

        return $value;
    }
1280910
public function sanitize( $value ) {
		$sanitize = $this->sanitize_callback;

		if ( \is_callable( $sanitize ) ) {
			return $sanitize( $value );
		}

		return $value;
	}
900870
public function parseValue($value)
    {
        if (strlen($value) === 0) {
            return $value;
        }

        if ($value[0] === '"' || $value[0] === "'") {
            $value = substr($value, 1, -1);
        }

        $value = stripslashes($value);

        return $value;
    }
759449
public function clean($value)
  {
    // First prune whitespace.
    $cleaner = PruneWhitespaceCleaner::get();
    $value   = $cleaner->clean($value);

    // If the value is empty return immediately,
    if ($value==='' || $value===null || $value===false)
    {
      return null;
    }

    // Split the URL in parts.
    $parts = parse_url($value);
    if (!is_array($parts))
    {
      return $value;
    }

    return Url::unParseUrl($parts, 'http');
  }
1054766
public function sanitize_slack_url( $value ) {
		$value = trim( (string) $value );

		if ( ! $value ) {
			return '';
		}

		$url = filter_var( $value, FILTER_VALIDATE_URL );

		if ( ! $url ) {
			add_settings_error(
				'soter_slack_url',
				'invalid_soter_slack_url',
				'Provided Slack webhook URL does not appear to be a valid URL.'
			);

			return $this->slack_url;
		}

		$host = wp_parse_url( $url, PHP_URL_HOST );

		if ( 'hooks.slack.com' !== $host ) {
			add_settings_error(
				'soter_slack_url',
				'invalid_soter_slack_url',
				sprintf(
					'Slack webhook URL host must be hooks.slack.com - given %s.',
					$host
				)
			);

			return $this->slack_url;
		}

		return $url;
	}
456465
private function sanitize($value)
    {
        if ($value === null) {
            $value = 'null';
        }

        if (is_array($value)) {
            $value = 'array';
        }

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

        return $value;
    }
916989
public function filter($value)
    {
        if (!is_string($value) && !is_array($value)) {
            return $value;
        }
        return str_replace($this->search, $this->replacement, $value);
    }
636271
private function stringEscaped($value)
    {
        $value = $this->string($value);
        $value = str_replace(self::$strReplaceFrom, self::$strReplaceTo, $value);

        return $value;
    }
199094
function fromString($value)
    {
        $this->clear();
        $this->orignalValue = $this->returnValue  = (string) $value;
        return $this->parse();
    }
1147270
protected function _sanitize($value)
    {
        // If instance of AnConfig casting to string will make it encode itself to JSON
        if ($value instanceof AnConfig) {
            $result = (string) $value;
        } else {
            //Don't re-encode if the value is already in json format
            if (is_string($value) && (json_decode($value) !== null)) {
                $result = $value;
            } else {
                $result = json_encode($value);
            }
        }

        return $result;
    }
1046176
public function filter($value)
    {
        if (!is_scalar($value) && !is_array($value)) {
            return $value;
        }

        // a unicode safe way of converting characters to \x00\x00 notation
        $pregQuotedSeparator = preg_quote($this->separator, '#');

        if (StringUtils::hasPcreUnicodeSupport()) {
            $patterns = [
                '#(' . $pregQuotedSeparator.')(\P{Z}{1})#u',
                '#(^\P{Z}{1})#u',
            ];
            if (!extension_loaded('mbstring')) {
                $replacements = [
                    function ($matches) {
                        return strtoupper($matches[2]);
                    },
                    function ($matches) {
                        return strtoupper($matches[1]);
                    },
                ];
            } else {
                $replacements = [
                    function ($matches) {
                        return mb_strtoupper($matches[2], 'UTF-8');
                    },
                    function ($matches) {
                        return mb_strtoupper($matches[1], 'UTF-8');
                    },
                ];
            }
        } else {
            $patterns = [
                '#(' . $pregQuotedSeparator.')([\S]{1})#',
                '#(^[\S]{1})#',
            ];
            $replacements = [
                function ($matches) {
                    return strtoupper($matches[2]);
                },
                function ($matches) {
                    return strtoupper($matches[1]);
                },
            ];
        }

        $filtered = $value;
        foreach ($patterns as $index => $pattern) {
            $filtered = preg_replace_callback($pattern, $replacements[$index], $filtered);
        }
        return $filtered;
    }
314451
protected function cleanValue($value)
	{
		if (is_array($value)) {
			return array_map(function ($v) {
				return $this->cleanValue($v);
			}, $value);
		} else {
			return stripslashes($value);
		}
	}
1341720
private function formatEmpty($value)
    {
        if (empty($value = \trim($value))) {
            return $value;
        }

        return $this->formatValue($value);
    }
1084298
protected function _sanitize($value)
    {
        //Tidy is not installed, return the input
        if ($tidy = $this->getTidy($value)) {
            if ($tidy->cleanRepair()) {
                $value = (string) $tidy;
            }
        }

        return $value;
    }
346795
protected function _sanitize($value)
    {
        $value      = trim(strtolower($value));
        $pattern    = '/[^a-f0-9]*/';
        return substr(preg_replace($pattern, '', $value), 0, 32);
    }
1344680
protected function _sanitize($value)
    {
        $value = parent::_sanitize($value);
        $pattern = '/[()<\/>\"\']*/';
        $value = preg_replace_callback($pattern, function($matches) { return '';} , $value);

        return $value;
    }
627331
protected function parseValue($value) {
		$value = trim($value);
		if ('' == $value) {
			//return as boolean
			return true;
		}
		return $this->valueParser->parse($value); 
	}