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"; } }
/** * Parse string into its InternetAddresses. * * <code> * $p= new InternetAddressParser(); * try { * $addr= $p->parse('"Kiesel, Alex" <*****@*****.**>, Christian Lang <*****@*****.**>'); * } catch(FormatException $e)) { * $e->printStackTrace(); * } * * foreach (array_keys($addr) as $idx) { Console::writeLine($addr[$idx]->toString()); } * * </code> * * @return InternetAddress[] * @throws lang.FormatException in case the string is malformed */ public function parse($str) { $result = array(); $st = new StringTokenizer($str, ','); $st->hasMoreTokens() && ($tok = $st->nextToken()); while ($tok) { // No " in this string, so this contains one address if (FALSE === ($pos = strpos($tok, '"'))) { $result[] = InternetAddress::fromString($tok); $tok = $st->nextToken(); continue; } // When having at least one double-quote, we have to make sure, the address delimiter ',' // is not inside the quotes. If so, search the next delimiter and perform this check again. // Additionally, inside a quote, the quote delimiter may be quoted with \ itself. Catch // that case as well. $inquot = 0; for ($i = 0; $i < strlen($tok); $i++) { if ($tok[$i] == '"' && (!$inquot || ($i == 0 || $tok[$i - 1] != '\\'))) { $inquot = 1 - $inquot; } } if ($inquot) { if (!$st->hasMoreTokens()) { throw new FormatException('Cannot parse string: no ending delimiter found.'); } $tok = $tok . ',' . $st->nextToken(); continue; } $result[] = InternetAddress::fromString($tok); // Handle next token $tok = $st->nextToken(); } return $result; }
public function Parse() { if ($this->BugReport == NULL) { return false; } $tokenizer = new StringTokenizer($this->BugReport, ":\t\n"); if (!$tokenizer->HasNextToken()) { return false; } $key = 0; $value = NULL; $count = 0; while ($tokenizer->HasNextToken()) { $token = $tokenizer->GetNextToken(); if ($count % 2 != 0) { $value = $token; $this->Data[$key] = $value; } else { $key = $token; } $count++; } return true; }
public function Parse() { if ($this->BugReport == NULL) { return false; } $tokenizer = new StringTokenizer($this->BugReport, "</>"); if (!$tokenizer->HasNextToken()) { return false; } $key = 0; $value = NULL; $intag = false; while ($tokenizer->HasNextToken()) { $i = 0; if ($intag == false) { $key = $tokenizer->GetNextToken(); if (!is_numeric($key)) { return false; } $intag = true; } else { if ($value == NULL) { $value = $tokenizer->GetNextToken(); } else { $i = $tokenizer->GetNextToken(); if (is_numeric($i) && $i == $key) { $this->Data[$key] = $value; $intag = false; $value = NULL; $key = 0; $i = 0; } else { return false; } } } } return true; }
public function __construct($str) { parent::__construct($str, "\t\n"); }
/** * 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; }
/** * Parse AICC HACP * * This function parses an AICC HACP putparam * @param string $aiccdata - The contents of an AICC putparam */ public function parsehacp($aiccdata) { $AICCTokens = new StringTokenizer($aiccdata, "\r\n"); $AICCToken = ""; while ($AICCTokens->hasMoreTokens()) { if (!startsWith($AICCToken, "[")) { $AICCToken = trim($AICCTokens->nextToken()); } if (!$AICCToken == "") { //Find block and set if (startsWith($AICCToken, "[")) { $this->key = strtolower($AICCToken); $this->block = strtolower($AICCToken); if ($AICCTokens->hasMoreTokens()) { $AICCToken = trim($AICCTokens->nextToken()); } else { return; } } if ($this->block == "[core_lesson]" || $this->block == "[comments]") { if (!startsWith($AICCToken, "[") && !$AICCToken == "") { $this->value = $AICCToken; if ($this->setAICCCoreLesson() || !$this->setAICCComments()) { } } } else { $equal = strpos($AICCToken, '='); if ($equal != 0) { $this->key = strtolower(trim(substr($AICCToken, 0, $equal))); $this->value = trim(substr($AICCToken, $equal + 1)); } //&& !setAICCEvaluation() && !setAICCObjectivesStatus() && !setAICCStudentData() && !setAICCStudentDemographics() if (!$this->setAICCCore() && !$this->setAICCCoreLesson() && !$this->setAICCObjectivesStatus() && !$this->setAICCStudentData()) { if (!$this->setAICCStudentPreferences()) { } } } } } }