Example #1
0
 /**
  * @param string $string
  * @param TransformationFormat $encoding
  * @return static
  */
 public static function fromEncodedString($string, TransformationFormat $encoding)
 {
     $characters = StringUtility::split($string, $encoding);
     $mapper = function ($character) use($encoding) {
         return Codepoint::fromEncodedCharacter($character, $encoding);
     };
     return static::fromArray(array_map($mapper, $characters));
 }
Example #2
0
 /**
  * @param TransformationFormat $convertTo
  * @return string
  * @throws InvalidArgumentException
  */
 public function toEncodedCharacter(TransformationFormat $convertTo)
 {
     $character = pack('N', $this->value);
     $convertFrom = TransformationFormat::ofType(TransformationFormat::THIRTY_TWO_BIG_ENDIAN);
     return StringUtility::convertCharacter($character, $convertFrom, $convertTo);
 }