Build Buffer from string

In case \Normalizer is available, the utf-8 string will
be normalized with Normalization Form KD.

@param   string  $string
@return  \NEM\Core\Buffer
426246
static public function fromString($string, $paddingDirection = self::PAD_LEFT)
    {
        if (!class_exists("Normalizer")) {
            // Data representation Normalization not supported
            return new Buffer($string, null, $paddingDirection);
        }

        // Normalizer is used to avoid problems with UTF-8 serialization
        $normalized = \Normalizer::normalize($string, \Normalizer::FORM_KD);
        return new Buffer($normalized, null, $paddingDirection);
    }
532062
protected function normalizeString($string)
    {
        $value = $this->isAllUpperCase($string) ?
            strtolower(trim($string, '_-#$%')) :
            Str::snakeCase(trim($string, '_-#$%'));

        return strtolower(preg_replace('/[^a-zA-Z0-9(^@)]+/', '-', $value));
    }
1108046
public static function normalizeChars($string)
    {
        $normalizeChars = array(
            'Á' => 'A', 'À' => 'A', 'Â' => 'A', 'Ã' => 'A', 'Å' => 'A', 'Ä' => 'A', 'Æ' => 'AE', 'Ç' => 'C',
            'É' => 'E', 'È' => 'E', 'Ê' => 'E', 'Ë' => 'E', 'Í' => 'I', 'Ì' => 'I', 'Î' => 'I', 'Ï' => 'I', 'Ð' => 'Eth',
            'Ñ' => 'N', 'Ó' => 'O', 'Ò' => 'O', 'Ô' => 'O', 'Õ' => 'O', 'Ö' => 'O', 'Ø' => 'O',
            'Ú' => 'U', 'Ù' => 'U', 'Û' => 'U', 'Ü' => 'U', 'Ý' => 'Y', 'Ŕ' => 'R',

            'á' => 'a', 'à' => 'a', 'â' => 'a', 'ã' => 'a', 'å' => 'a', 'ä' => 'a', 'æ' => 'ae', 'ç' => 'c',
            'é' => 'e', 'è' => 'e', 'ê' => 'e', 'ë' => 'e', 'í' => 'i', 'ì' => 'i', 'î' => 'i', 'ï' => 'i', 'ð' => 'eth',
            'ñ' => 'n', 'ó' => 'o', 'ò' => 'o', 'ô' => 'o', 'õ' => 'o', 'ö' => 'o', 'ø' => 'o',
            'ú' => 'u', 'ù' => 'u', 'û' => 'u', 'ü' => 'u', 'ý' => 'y', 'ŕ' => 'r', 'ÿ' => 'y',

            'ß' => 'sz', 'þ' => 'thorn', 'º' => '', 'ª' => '', '°' => '',
        );
        return preg_replace('/[^0-9a-zA-Z !*\-$\(\)\[\]\{\},.;:\/\\#%&@+=]/', '', strtr($string, $normalizeChars));
    }
1076115
public function parseString($string)
    {

        $stringHelper = $this->container->get('opifer.content.string_helper');

        $string = $stringHelper->replaceLinks($string);

        return $string;
    }
1359417
public function append(string $string): self
    {
        return new self((string) $this.$string, $this->encoding);
    }
86180
public static function encode($string)
    {
        if (is_array($string)) {
            foreach ($string as $k => $substring) {
                $string[$k] = static::encode($substring);
            }
        } else {
            $string = urlencode($string);
        }

        return $string;
    }
989087
protected function convertString($string)
    {
        $charset = strtolower($this->getCharset());
        if (!in_array($charset, ['utf-8', 'iso-8859-1', 'iso-8859-15', ''])) {
            return mb_convert_encoding($string, $charset, 'utf-8');
        }

        return $string;
    }
422639
public function transform($string)
    {
        $string = Normalizer::normalize($string, $this->form);
        if ($string === null) {
            throw new UnexpectedValueException('Normalizer error.');
        }
        return $string;
    }
262617
protected static function strLen($string){
    $encoding = function_exists('mb_detect_encoding') ? mb_detect_encoding($string) : false;
    return $encoding ? mb_strlen($string, $encoding) : strlen($string);
  }
832360
public static function romanize($string)
    {
        foreach (self::$chars as $regex => $replacement) {
            // u enables Unicode
            $string = preg_replace($regex . 'u', $replacement, $string);
        }

        return $string;
    }
448140
public static function fromHexString(string $string) : Colour
    {
        list($r, $g, $b) = ColourStringParser::parseHexString($string);

        return new self($r, $g, $b);
    }
228958
public function convertToUTF8Ansii($string){
			if (is_array($string)) {
				foreach ($string as $k => $v) {
					$string[$k] = $this->convertToUTF8Ansii($v);
				}
			} else if (is_string ($string)) {
				return mb_convert_encoding($string, "UTF-8", "Windows-1252");
			}
			return $string;
		}
820933
public static function strlen( $string )
    {
        if ( false === ( $_encoding = static::mbSupported( $string ) ) )
        {
            return strlen( $string );
        }

        return mb_strwidth( $string, $_encoding );
    }
413525
public static function normalizeColumn($string)
    {
        $parts = explode('_', $string);

        foreach ($parts as &$part) {
            $part = ucfirst($part);
        }

        return join(' ', $parts);
    }
655025
public static function fromString( $string )
	{
#		$string		= trim( $string );
		$parts		= explode( "\r\n\r\n", $string );
		$response	= new Net_HTTP_Response;
		while( $part = array_shift( $parts ) )
		{
			$pattern	= '/^([A-Z]+)\/([0-9.]+) ([0-9]{3}) ?(.+)?/';
			if( !preg_match( $pattern, $part ) )
			{
				array_unshift( $parts, $part );
				break;
			}
			if( !$response->headers->getFields() )
				$response	= self::parseHeadersFromString( $part );
		};
		$body	= implode( "\r\n\r\n", $parts );

/*		$encodings	= $response->headers->getField( 'content-encoding' );
		while( $encoding = array_pop( $encodings ) )
		{
			$method	= $encoding->getValue();
			$body	= Net_HTTP_Response_Decompressor::decompressString( $body, $method );
		}*/
		$response->setBody( $body );
		return $response;
	}
483704
public function format($string) {
        if ($this->isAnsiEnabled()) {
            return $this->formatAnsi($string);
        }

        return $this->formatPlain($string);
    }
1298001
public static function strlenForGbk($string)
	{
		$l = strlen($string);
		$p = $c = 0;
		while ($p < $l)
		{
			if ($string[$p] > "\x80")
				$p += 2;
			else
				$p++;
			$c++;
		}
		return $c;
	}