code: 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;
      }
docs: Internal helper function to convert string encodings.
  
  @param string|StringBuilder $string         The input string.
  @param string               $outputEncoding The output encoding.
  
  @return string