示例#1
0
 public function testCanEncode()
 {
     $chars = implode("", array_map('chr', range(32, 126)));
     $this->assertTrue(\r8\Transform\MIME\Raw::canEncode($chars));
     $chars = array_merge(range(1, 31), range(127, 255));
     foreach ($chars as $char) {
         if (\r8\Transform\MIME\Raw::canEncode(chr($char))) {
             $this->fail("failed asserting that character with the ascii " . "code " . $char . " can't be raw encoded");
         }
     }
 }
示例#2
0
 /**
  * Encodes a string
  *
  * @param mixed $value The value to encode
  * @return mixed The result of the encoding process
  */
 public function to($string)
 {
     // If we can raw encode, always select that option
     if (\r8\Transform\MIME\Raw::canEncode($string)) {
         $encode = $this->apply(new \r8\Transform\MIME\Raw());
         return $encode->to($string);
     }
     $bEncode = $this->apply(new \r8\Transform\MIME\B());
     $qEncode = $this->apply(new \r8\Transform\MIME\Q());
     $bEncoded = $bEncode->to($string);
     $qEncoded = $qEncode->to($string);
     if (strlen($bEncoded) <= strlen($qEncoded)) {
         return $bEncoded;
     } else {
         return $qEncoded;
     }
 }