Pads the given string $str with the PKCS7 padding scheme, so that its
length shall be a multiple of $blocksize.
@param $str A string to pad.
@param $blocksize The block size.
@return The resulting padded string.
777842
private static function addPKCS7Padding($str, $blocksize)
	{
		$len = strlen($str);
		$pad = $blocksize - ($len % $blocksize);
		return $str . str_repeat(chr($pad), $pad);
	}
18618
public static function padLeft(string $s, int $length, string $pad = ' '): string
    {
        $length -= \mb_strlen($s);
        if ($length <= 0) {
            return $s;
        }

        $padLen = \mb_strlen($pad);

        return \str_repeat($pad, (int) ($length / $padLen)) . \mb_substr($pad, 0, $length % $padLen) . $s;
    }
1365096
public function decrypt(string $str): string
    {
        return openssl_decrypt($str, self::CIPHER_METHOD, $this->key, 0, $this->getIv());
    }
914298
public static function padBoth(string $str, int $length, string $with = ' ', string $encoding = null) : string
    {
        return static::pad($str, $length, $with, STR_PAD_BOTH, $encoding);
    }
154038
public static function padLeft(string $str, int $length, string $with = ' ', string $encoding = null) : string
    {
        return static::pad($str, $length, $with, STR_PAD_LEFT, $encoding);
    }
248240
private static function _pad($text, $blocksize) {
        $pad = $blocksize - (strlen($text) % $blocksize);
        $textWithPadding = $text . str_repeat(chr($pad), $pad); 
        return $textWithPadding;
    }
970116
public function SecureHeader($str) {
    $str = str_replace("\r", '', $str);
    $str = str_replace("\n", '', $str);
    return trim($str);
  }
618762
protected function _stringHasR($str) {
		foreach (func_get_args() as $arg) {
			if (strpos($arg, "\r") !== false) {
				return true;
			}
		}
		return false;
	}
920498
public function encryptByConfig($str)
    {
        if ($this->isSingle()) {
            if ($security_key = $this->getConfigByName('security_key')) {
                $str = $this->encrypt($str, hex2bin(md5($security_key)));
            }
            return $str;
        }
        return '';
    }
1191566
public function stripPadding($block, $data) {
    $pad = ord($data[($len = strlen($data)) - 1]);

    /* Check that what we have at the end of the string really is padding, and if it is remove it. */
    if ($pad && $pad < $block && preg_match('/' . chr($pad) . '{' . $pad . '}$/', $data)) {
      return substr($data, 0, -$pad);
    }
    return $data;
  }
1264917
def removeSpacePadding(str, blocksize=AES_blocksize):
    '' 
    pad_len = 0    
    for char in str[::-1]: # str[::-1] reverses string
        if char == ' ':
            pad_len += 1
        else:
            break

    str = str[:-pad_len]
   
    return str
1060166
def appendRandomLenPadding(str, blocksize=AES_blocksize):
  ''
  pad_len = paddingLength(len(str), blocksize) - 1
  
  from os import urandom
  
  padding = urandom(pad_len)+chr(pad_len)
  
  return str + padding
1354471
private function _repack_utf7(string $str): string
    {
        return (string) \preg_replace_callback(
            '#\+([\\p{L}0-9]+)\-#ui',
            function ($matches) {
                return $this->_repack_utf7_callback($matches);
            },
            $str
        );
    }
532941
public function fromBin(string $str):string {
		$this->checkLength($str);
		$this->checkBin($str);

		// Base32 works on the first 5 bits of a byte, so we insert blanks to pad it out
		$str = preg_replace('/(.{5})/', '000$1', $str);

		// We need a string divisible by 5
		$length = strlen($str);
		$rbits = $length&7;

		if($rbits > 0){
			// Excessive bits need to be padded
			$ebits = substr($str, $length-$rbits);
			$str = substr($str, 0, $length-$rbits).'000'.$ebits.str_repeat('0', 5-strlen($ebits));
		}

		preg_match_all('/.{8}/', $str, $chrs);

		$chrs = array_map(function($str){
			return $this->charset[bindec($str)];
		}, $chrs[0]);

		return implode('', $chrs);
	}
21180
protected function toBytes($str){
        $val = substr(trim($str), 0, strlen($str)-1);
        $last = strtolower($str[strlen($str)-1]);
        switch($last) {
            case 'g': $val *= 1024;
            case 'm': $val *= 1024;
            case 'k': $val *= 1024;
        }
        return $val;
    }
1360541
private function _toupper($str)
    {
        // string can containing HTML tags
        $chunks = preg_split('/(<[^>]*>)/', $str, null, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);

        // convert toupper only the text between HTML tags
        foreach ($chunks as $idx => $chunk) {
            if ($chunk[0] != '<') {
                $chunks[$idx] = $this->_strtoupper($chunk);
            }
        }

        return implode($chunks);
    }
522178
protected function _blockquote($str) {
		$str=preg_replace('/(?<=^|\n)\h?>\h?(.*?(?:\n+|$))/','\1',$str);
		return strlen($str)?
			('<blockquote>'.$this->build($str).'</blockquote>'."\n\n"):'';
	}