Removes escapings from a given argument string and trims the outermost
quotes.

This method is meant as a helper for regular expression results.

@param string $quotedValue Value to unquote
@return string Unquoted value
179495
protected function unquoteString($quotedValue)
    {
        switch ($quotedValue[0]) {
            case '"':
                $value = str_replace('\\"', '"', preg_replace('/(^"|"$)/', '', $quotedValue));
                break;
            case "'":
                $value = str_replace("\\'", "'", preg_replace('/(^\'|\'$)/', '', $quotedValue));
                break;
            default:
                $value = $quotedValue;
        }
        return str_replace('\\\\', '\\', $value);
    }
838555
public function quoteIdentifiers($quoteStr)
    {
        if ($quoteStr instanceof \Closure || is_resource($quoteStr)) {
            throw new \InvalidArgumentException(
                "Invalid value to be quote, quote value could not be instance of `Closure` or as a `Resource`",
                E_USER_ERROR
            );
        }

        $quoteStr = $this->trimTableSelector($quoteStr);
        if (is_array($quoteStr)) {
            foreach ($quoteStr as $key => $value) {
                $quoteStr[$key] = $this->quoteIdentifiers($value);
            }
            return $quoteStr;
        } elseif (is_object($quoteStr)) {
            foreach (get_object_vars($quoteStr) as $key => $value) {
                $quoteStr->{$key} = $this->quoteIdentifiers($value);
            }
            return $quoteStr;
        }

        $return = $this->quoteIdentifier($quoteStr);

        return $return;
    }
1222648
private function quoteAttributeValue($s) {
	    $quotedString = $this->collapseWhitespace($s);
	    $quotedString = preg_replace('/\\\\/', '\\\\\\\\', $quotedString);
	    $quotedString = preg_replace('/\\;/', '\\;', $quotedString);
	    $quotedString = preg_replace('/\\)/', '\\)', $quotedString);
	
	    return $quotedString;
	}
13466
def _trim_value(self, value):
        

        if value[0] == '"':
            assert value[-1] == '"'
            value = value[1:-1].replace('\\"', '"').replace("\\\\", "\\")
            return Parser._unescape_re.sub(Parser._unescape_fn, value)
        return value
90026
protected function _strReplaceOutsideQuotes(){
        
        $re_valid = '/
            # Validate string having embedded quoted substrings.
            ^                           # Anchor to start of string.
            (?:                         # Zero or more string chunks.
              "[^"\\\\]*(?:\\\\.[^"\\\\]*)*"  # Either a double quoted chunk,
            | \'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\'  # or a single quoted chunk,
            | [^\'"\\\\]+               # or an unquoted chunk (no escapes).
            )*                          # Zero or more string chunks.
            \z                          # Anchor to end of string.
            /sx';
        if (!preg_match($re_valid, $this->subject)) {
            throw new StringHelperException("Subject string is not valid in the replace_outside_quotes context.");
        }
        $re_parse = '/
            # Match one chunk of a valid string having embedded quoted substrings.
              (                         # Either $1: Quoted chunk.
                "[^"\\\\]*(?:\\\\.[^"\\\\]*)*"  # Either a double quoted chunk,
              | \'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\'  # or a single quoted chunk.
              )                         # End $1: Quoted chunk.
            | ([^\'"\\\\]+)             # or $2: an unquoted chunk (no escapes).
            /sx';
        
        return preg_replace_callback($re_parse, array($this, '_strReplaceOutsideQuotesCb'), $this->subject);
    }
361319
function (vValue) {
			var sStringified,
				bEscaped = false,
				sResult = "",
				i, c;

			sStringified = JSON.stringify(vValue);
			if (sStringified === undefined) {
				return undefined;
			}
			for (i = 0; i < sStringified.length; i += 1) {
				switch (c = sStringified.charAt(i)) {
					case "'": // a single quote must be escaped (can only occur in a string)
						sResult += "\\'";
						break;
					case '"':
						if (bEscaped) { // a double quote needs no escaping (only in a string)
							sResult += c;
							bEscaped = false;
						} else { // string begin or end with single quotes
							sResult += "'";
						}
						break;
					case "\\":
						if (bEscaped) { // an escaped backslash
							sResult += "\\\\";
						}
						bEscaped = !bEscaped;
						break;
					default:
						if (bEscaped) {
							sResult += "\\";
							bEscaped = false;
						}
						sResult += c;
				}
			}
			return sResult;
		}
1199643
protected static function sanitiseVariableValue($value)
        {
            $value = trim($value);

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

            if (strpbrk($value[0], '"\'') !== false) { // value starts with a quote
                $quote = $value[0];

                $regexPattern = sprintf('/^
                    %1$s          # match a quote at the start of the value
                    (             # capturing sub-pattern used
                     (?:          # we do not need to capture this
                      [^%1$s\\\\] # any character other than a quote or backslash
                      |\\\\\\\\   # or two backslashes together
                      |\\\\%1$s   # or an escaped quote e.g \"
                     )*           # as many characters that match the previous rules
                    )             # end of the capturing sub-pattern
                    %1$s          # and the closing quote
                    .*$           # and discard any string after the closing quote
                    /mx',
                    $quote
                );

                $value = preg_replace($regexPattern, '$1', $value);
                $value = str_replace("\\$quote", $quote, $value);
                $value = str_replace('\\\\', '\\', $value);
            } else {
                $parts = explode(' #', $value, 2);
                $value = $parts[0];
            }

            return trim($value);
        }
18356
@SuppressWarnings("fallthrough")
    protected void quotedString() {
        int pos = bp;
        nextChar();

        loop:
        while (bp < buflen) {
            switch (ch) {
                case '\n': case '\r': case '\f':
                    newline = true;
                    break;

                case ' ': case '\t':
                    break;

                case '"':
                    nextChar();
                    // trim trailing white-space?
                    return;

                case '@':
                    if (newline)
                        break loop;

            }
            nextChar();
        }
    }
1170269
public static function escapeAssertion($s)
    {
        if (0 === strpos($s, 'r.')) {
            $s = substr_replace($s, 'r_', 0, 2);
        }
        if (0 === strpos($s, 'p.')) {
            $s = substr_replace($s, 'p_', 0, 2);
        }

        $s = preg_replace_callback("~(\|| |=|\)|\(|&|<|>|,|\+|-|!|\*|\/)(r|p)(\.)~", function ($m) {
            return $m[1].$m[2].'_';
        }, $s);

        return $s;
    }
256949
public function trimProperty(string $propertyValue)
    {
        switch ($propertyValue) {
            case 'true':
                $propertyValue = true;

                break;
            case 'false':
                $propertyValue = false;

                break;
            default:
                $propertyValue = trim($propertyValue);

                break;
        }

        return $propertyValue;
    }
424758
protected function _str_replace_outside_quotes()
        {
            $re_valid = '/
                # Validate string having embedded quoted substrings.
                ^                           # Anchor to start of string.
                (?:                         # Zero or more string chunks.
                  "[^"\\\\]*(?:\\\\.[^"\\\\]*)*"  # Either a double quoted chunk,
                | \'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\'  # or a single quoted chunk,
                | [^\'"\\\\]+               # or an unquoted chunk (no escapes).
                )*                          # Zero or more string chunks.
                \z                          # Anchor to end of string.
                /sx';

            if (!preg_match($re_valid, $this->subject)) {
                throw new OneStringException("Subject string is not valid in the replace_outside_quotes context.");
            }

            $re_parse = '/
                # Match one chunk of a valid string having embedded quoted substrings.
                  (                         # Either $1: Quoted chunk.
                    "[^"\\\\]*(?:\\\\.[^"\\\\]*)*"  # Either a double quoted chunk,
                  | \'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\'  # or a single quoted chunk.
                  )                         # End $1: Quoted chunk.
                | ([^\'"\\\\]+)             # or $2: an unquoted chunk (no escapes).
                /sx';

            return preg_replace_callback($re_parse, array($this, '_strReplaceOutsideQuotesCb'), $this->subject);
        }
486028
private function _extractValue()
    {
        $value = Resources::EMPTY_STRING;

        if ($this->_pos < strlen($this->_value)) {
            $ch = $this->_value[$this->_pos];

            if ($ch == '"' || $ch == '\'') {
                // Value is contained between double quotes or skipped single quotes.
                ++$this->_pos;
                $value = $this->_extractString($ch);
            } else {
                $firstPos = $this->_pos;
                $isFound = false;

                while ($this->_pos < strlen($this->_value) && !$isFound) {
                    $ch = $this->_value[$this->_pos];

                    if ($ch == ';') {
                        $isFound = true;
                    } else {
                        ++$this->_pos;
                    }
                }

                $value = rtrim(
                    substr($this->_value, $firstPos, $this->_pos - $firstPos)
                );
            }
        }

        return $value;
    }
1112715
public function stringValue(string $allowedNext = ',;)'): string
    {
        $value = '';

        if ($this->isEnd()) {
            throw $this->createSyntaxException('StringValue');
        }

        if ('"' === $this->data[$this->cursor]) {
            $this->moveCursor('"');

            while ("\n" !== $c = mb_substr($this->data, $this->char, 1)) {
                if ('"' === $c) {
                    if ($this->cursor + 1 === $this->end) {
                        break;
                    }
                    if ('"' !== mb_substr($this->data, $this->char + 1, 1)) {
                        break;
                    }

                    $this->moveCursor($c);
                }

                $value .= $c = mb_substr($this->data, $this->char, 1);
                $this->moveCursor($c);

                if ($this->cursor === $this->end) {
                    throw $this->createFormatException(StringLexerException::MISSING_END_QUOTE);
                }
            }

            if ("\n" === $c) {
                throw $this->createFormatException(StringLexerException::MISSING_END_QUOTE);
            }

            $this->moveCursor('"');

            $this->skipWhitespace();

            // Detect an user error like: "foo"bar"
            if ($this->cursor < $this->end && !$this->isGlimpse('/['.preg_quote($allowedNext, '/').']/A')) {
                throw $this->createFormatException(StringLexerException::VALUE_QUOTES_MUST_ESCAPE);
            }

            return $value;
        }

        $allowedNextRegex = '/['.preg_quote($allowedNext, '/').']/A';

        while ($this->cursor < $this->end && "\n" !== $c = mb_substr($this->data, $this->char, 1)) {
            if ('"' === $c) {
                throw $this->createFormatException(StringLexerException::QUOTED_VALUE_REQUIRE_QUOTING);
            }

            if ($this->isGlimpse($allowedNextRegex)) {
                break;
            }

            if ($this->isGlimpse('/[<>[\](),;~!*?=&*]/A')) {
                throw $this->createFormatException(StringLexerException::SPECIAL_CHARS_REQ_QUOTING);
            }

            $value .= $c;
            $this->moveCursor($c);
        }

        $value = rtrim($value);

        if (preg_match('/\s+/', $value)) {
            throw $this->createFormatException(StringLexerException::SPACES_REQ_QUOTING);
        }

        return $value;
    }
77157
protected static String removeQuotes(String quotedString, boolean quotesRequired) {
        // support both quoted and non-quoted
        if (quotedString.length() > 0 && quotedString.charAt(0) != '"' && !quotesRequired) {
            return quotedString;
        } else if (quotedString.length() > 2) {
            return quotedString.substring(1, quotedString.length() - 1);
        } else {
            return "";
        }
    }
1043054
def escape_quotes(self, val):
        
        if self.is_string(val) and self._in_quotes(val, self.quote):
            # make sure any previously escaped quotes are not re-escaped
            middle = self.remove_quotes(val).replace("\\" + self.quote, self.quote)
            middle = middle.replace(self.quote, "\\" + self.quote)
            val = self.add_quotes(middle)

        return val
540007
protected function _processFilter($fieldValue)
    {
        $stringModifier = getStr();

        //removing % symbols
        $fieldValue = $stringModifier->preg_replace("/^%|%$/", "", trim($fieldValue));

        return $stringModifier->preg_replace("/\s+/", " ", $fieldValue);
    }
1077085
protected function parseValidatorAnnotation($validateValue)
    {
        $matches = [];
        if ($validateValue[0] === '$') {
            $parts = explode(' ', $validateValue, 2);
            $validatorConfiguration = ['argumentName' => ltrim($parts[0], '$'), 'validators' => []];
            preg_match_all(self::PATTERN_MATCH_VALIDATORS, $parts[1], $matches, PREG_SET_ORDER);
        } else {
            $validatorConfiguration = ['validators' => []];
            preg_match_all(self::PATTERN_MATCH_VALIDATORS, $validateValue, $matches, PREG_SET_ORDER);
        }
        foreach ($matches as $match) {
            $validatorOptions = [];
            if (isset($match['validatorOptions'])) {
                $validatorOptions = $this->parseValidatorOptions($match['validatorOptions']);
            }
            $validatorConfiguration['validators'][] = ['validatorName' => $match['validatorName'], 'validatorOptions' => $validatorOptions];
        }
        return $validatorConfiguration;
    }