/* Collapse multiple whitespace characters into a single ' ' and backslash escape '\',
and '(' characters from a string.

@param $s
@return string
321812
private function quoteApplicationVersion($s)
    {
        $quotedString = preg_replace('/ {2,}|\s/', ' ', $s);
        $quotedString = preg_replace('/\\\\/', '\\\\\\\\', $quotedString);
        $quotedString = preg_replace('/\\(/', '\\(', $quotedString);
        return $quotedString;
    }
1370314
public static function escape($string)
    {
        // when we have a numeric string only, nothing needs to be done
        if (is_numeric($string)) {
            return $string;
        }

        // when no whitespaces are in the query we can also just escape the special characters
        if (preg_match('/\W/', $string) != 1) {
            return static::escapeSpecialCharacters($string);
        }

        // when there are no quotes inside the query string we can also just escape the whole string
        $hasQuotes = strrpos($string, '"') !== false;
        if (!$hasQuotes) {
            return static::escapeSpecialCharacters($string);
        }

        $result = static::tokenizeByQuotesAndEscapeDependingOnContext($string);

        return $result;
    }
152416
def collapse_spaces(text):
    """"""
    if not isinstance(text, six.string_types):
        return text
    return COLLAPSE_RE.sub(WS, text).strip(WS)
1143539
private function trimSpecialsChars($s)
    {
        if (count($this->getNotReplacedChars()) == 0) {
            $reg = '~[^-a-z0-9_]+~';
        } else {
            $reg = '~[^-a-z0-9_' . implode('', $this->getNotReplacedChars()) .']+~';
        }
        return preg_replace($reg, '', $s);
    }
935852
private function quoteApplicationVersion($s) {
	    $quotedString = $this->collapseWhitespace($s);
	    $quotedString = preg_replace('/\\\\/', '\\\\\\\\', $quotedString);
	    $quotedString = preg_replace('/\\(/', '\\(', $quotedString);
	
	    return $quotedString;
    }
1367226
public static function escapeJidLocalpart($s)
    {
        $result = '';

        $chars = [' ', '"', '&', '\'', '/', ':', '<', '>', '@'];
        $escapes = ['20', '22', '26', '27', '2f', '3a', '3c', '3e', '40', '5c'];

        for($i = 0; $i < strlen($s); $i++) {
            if($s{$i} === '\\') {
                if(in_array($s{$i+1}.$s{$i+2}, $escapes)) {
                    $result .= '\\5c';
                } else {
                    $result .= $s{$i};
                }
            } else if(in_array($s{$i}, $chars)) {
                $result .= '\\'.dechex(ord($s{$i}));
            } else {
                $result .= $s{$i};
            }
        }

        return $result;
    }
1190802
private function _replaceDelimiters ($s)
    {
        foreach ($this->getWordDelimiters() as $delimiter) {
            if ($delimiter == $this->getDelimiterReplacement()) {
                continue;
            }
            if (in_array($delimiter, $this->getNotReplacedChars())) {
                continue;
            }
            
            $s = str_replace($delimiter, $this->getDelimiterReplacement(), $s);
        }
        return $s;
    }
60916
public static String collapseWhitespace(final String value) {
        validate(value, NULL_STRING_PREDICATE, NULL_STRING_MSG_SUPPLIER);
        return value.trim().replaceAll("\\s\\s+", " ");
    }
920530
private function toLowerChars($s)
    {
        $lowerFilter = new \Zend\Filter\StringToLower;
        $lowerFilter->setEncoding('utf-8');
        return $lowerFilter->filter($s);
    }
895037
public function sanitizeNamespace($ns)
    {
        // dots to underscores
        $ns = str_replace(".", "_", $ns);

        // spaces to underscores
        $ns = str_replace(" ", "_", $ns);

        // dashes to underscores
        $ns = str_replace("-", "_", $ns);

        // Alpha numeric
        $ns = preg_replace("/[^A-Za-z0-9\.\_\- ]/", '', $ns);

        return $ns;
    }
223083
function jsEscape(s) {
  var result = '"';
  for (var i = 0; i < s.length; i++) {
    let cp = s.charCodeAt(i);
    let special = specialEscape[cp];
    if (special !== undefined) {
      result += special;
    } else if (cp >= 0x20 && cp <= 0x7e) {
      result += String.fromCodePoint(cp);
    } else {
      result += '\\u' + zeroPaddedHex(cp, 4);
    }
  }
  result += '"';
  return result;
}
287872
public static function spaceless(string $string): string
	{
		$string = self::trim($string);
		$string = self::replace($string, '#\s{2,}#', ' ');
		return $string;
	}
646361
private function replaceDoubleDelimiterReplacementWithSingle($s)
    {
        $doubleDelimiterReplacement = $this->getDelimiterReplacement() . $this->getDelimiterReplacement();
        while (strpos($s, $doubleDelimiterReplacement) !== false) {
            $s = str_replace($doubleDelimiterReplacement, $this->getDelimiterReplacement(), $s);
        }
        return $s;
    }
999529
public static function compress($string)
    {
        $result = '';

        $tokens = self::tokenize($string);

        $whitespace = true;
        foreach ($tokens as $token) {
            // Skip comment tokens
            if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_COMMENT || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) {
                continue;
            }
            // Remove extra whitespace in reserved words (e.g "OUTER     JOIN" becomes "OUTER JOIN")
            elseif ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_NEWLINE || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_TOPLEVEL) {
                $token[self::TOKEN_VALUE] = preg_replace('/\s+/',' ',$token[self::TOKEN_VALUE]);
            }

            if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_WHITESPACE) {
                // If the last token was whitespace, don't add another one
                if ($whitespace) {
                    continue;
                } else {
                    $whitespace = true;
                    // Convert all whitespace to a single space
                    $token[self::TOKEN_VALUE] = ' ';
                }
            } else {
                $whitespace = false;
            }

            $result .= $token[self::TOKEN_VALUE];
        }

        return rtrim($result);
    }
695415
function strip_whitespace (s) {
      if (options.strip_whitespace) {
        return s.replace(/\s*\n/g,"\n").replace(/(\r?\n){2,}/g,"\n\n");
      }
      return s;
    }
529502
public static function whitespace($str='', int $newlines=0) {
		ref\sanitize::whitespace($str, $newlines);
		return $str;
	}
350679
public static function charsToNormalTitle(string $s): string
    {
        if (is_array($s)) {
            $res = [];

            foreach ($s as $k => $v) {
                $res[$k] = strtr(ucfirst(strtolower($v)), ['_' => ' ']);
            }

            $s = $res;
        } elseif (is_string($s)) {
            $s = strtr(ucfirst(strtolower($s)), ['_' => ' ']);
        }

        return $s;
    }