public function testChangeEncoding() { $this->stringBuilder->changeEncoding('ISO-8859-1'); $this->assertEquals('ISO-8859-1', $this->stringBuilder->getEncoding()); $this->assertNotEquals($this->initialString, $this->stringBuilder->__toString()); $this->assertEquals(iconv('UTF-8', 'ISO-8859-1', $this->initialString), $this->stringBuilder->__toString()); }
/** * Internal helper function to convert string encodings. * * @param string|StringBuilder $string The input string. * @param string $outputEncoding The output encoding. * * @return string */ private static function convertString($string, $outputEncoding) { if ($string instanceof StringBuilder) { $inputEncoding = $string->getEncoding(); } else { $inputEncoding = mb_detect_encoding((string) $string); } $string = (string) $string; if ($inputEncoding != $outputEncoding) { $string = iconv($inputEncoding, $outputEncoding, $string); } return $string; }