Exemplo n.º 1
0
 /**
  * Parse attributes
  *
  * @param  string $string
  * @return [:string]
  */
 protected function attributesIn($string)
 {
     $st = new StringTokenizer($string, '="\'', true);
     $attributes = [];
     while ($st->hasMoreTokens()) {
         $token = $st->nextToken();
         if ('=' === $token) {
             $name = trim($last);
         } else {
             if ('"' === $token || "'" === $token) {
                 $value = $st->nextToken($token);
                 $st->nextToken($token);
                 $attributes[$name] = self::$decode->__invoke(iconv($this->encoding, \xp::ENCODING, $value));
             } else {
                 $last = $token;
             }
         }
     }
     return $attributes;
 }
Exemplo n.º 2
0
 /**
  * Retrieve markup for specified text
  *
  * @param   string text
  * @return  string
  */
 public function markupFor($text)
 {
     $processor = $this->pushProcessor($this->processors['default']);
     $st = new StringTokenizer($text, '<>', $returnDelims = true);
     $out = '';
     while ($st->hasMoreTokens()) {
         if ('<' == ($token = $st->nextToken())) {
             $tag = $st->nextToken();
             // If this is an opening tag and a behaviour is defined for it, switch
             // states and pass control to the processor.
             // If this is a closing tag and behaviour is defined for it, switch back
             // state and return control to the previous processor.
             if (CharacterClass::$ALNUM->matches($tag[0])) {
                 $st->nextToken('>');
                 $attributes = array();
                 if (false !== ($p = strpos($tag, ' '))) {
                     $at = new StringTokenizer(substr($tag, $p + 1), ' ');
                     while ($at->hasMoreTokens()) {
                         $name = $at->nextToken('=');
                         $at->nextToken('"');
                         $attributes[$name] = $at->nextToken('"');
                         $at->nextToken(' ');
                     }
                     $lookup = strtolower(substr($tag, 0, $p));
                 } else {
                     $lookup = strtolower($tag);
                 }
                 if (isset($this->state[$lookup])) {
                     $processor = $this->pushProcessor($this->processors[$this->state[$lookup]]);
                     $out .= $processor->initialize($attributes);
                     continue;
                 } else {
                     $token = '<' . $tag . '>';
                 }
             } else {
                 if ('/' == $tag[0] && CharacterClass::$ALNUM->matches($tag[1])) {
                     $st->nextToken('>');
                     $lookup = ltrim(strtolower($tag), '/');
                     if (isset($this->state[$lookup])) {
                         $out .= $processor->finalize();
                         $processor = $this->popProcessor();
                         $st->nextToken("\n");
                         continue;
                     } else {
                         $token = '<' . $tag . '>';
                     }
                 } else {
                     $token = '<' . $tag;
                 }
             }
         }
         // Console::writeLine($processor->getClass(), ': "', $token, '"');
         $out .= $processor->process($token);
     }
     return $out;
 }
Exemplo n.º 3
0
 public function parseBody($multiPart, $output)
 {
     $inHeaders = false;
     $nextPart = '------_=_NextPart_' . self::BOUNDARY;
     $st = new StringTokenizer($multiPart, "\r\n");
     $out = '';
     while ($st->hasMoreTokens()) {
         $t = $st->nextToken();
         if (0 == strncmp($nextPart, $t, strlen($nextPart))) {
             $inHeaders = true;
             $out && $output->append($fileName, $out);
             continue;
         }
         // Header state
         if ($inHeaders) {
             if (0 == strlen($t)) {
                 // End of headers
                 sscanf($headers['Content-Type'], '%[^;]; name="%[^"]"', $type, $name);
                 $namer = explode('.', $name);
                 array_push($namer, ucfirst(array_pop($namer)));
                 $fileName = implode('/', $namer) . \xp::CLASS_FILE_EXT;
                 $out = '';
                 $inHeaders = false;
                 continue;
             }
             sscanf($t, "%[^:]: %[^\r]", $header, $value);
             $headers[$header] = $value;
             continue;
         }
         $out .= $t . "\n";
     }
 }