/** * 解码数据流. * * @param string $data 数据流. * * @return array */ public static function decode($data) { $parser = new TextParser($data); $cmdlen = $parser->getLength(); $cmd = $parser->getData($cmdlen); $datalen = $parser->getLength(); $data = $parser->getData($datalen); $ctx = array('command' => $cmd, 'data' => $data); return $ctx; }
public function __construct($content = "") { Object::__construct(); //FIXME: This should be done by TextParser parent::__construct($content); $this->texy = new SS_Texy(); $this->texy->setOutputMode(Texy::HTML5); $this->setAllowedTags($this->config()->get('allowed_tags')); $this->texy->headingModule->top = $this->config()->get('top_heading'); }
/** * Replace a "[sitetree_link id=n]" shortcode with a link to the page with the corresponding ID. * * @param array $arguments * @param string $content * @param TextParser $parser * @return string */ public static function link_shortcode_handler($arguments, $content = null, $parser = null) { if (!isset($arguments['id']) || !is_numeric($arguments['id'])) { return; } if (!($page = DataObject::get_by_id('SiteTree', $arguments['id'])) && !($page = Versioned::get_latest_version('SiteTree', $arguments['id'])) && !($page = DataObject::get_one('ErrorPage', '"ErrorPage"."ErrorCode" = \'404\''))) { return; // There were no suitable matches at all. } $link = Convert::raw2att($page->Link()); if ($content) { return sprintf('<a href="%s">%s</a>', $link, $parser->parse($content)); } else { return $link; } }
/** * @covers TextParser::__construct * @uses TextParser::setTemplatesDir * @uses TextParser::setLogFile * @expectedException Exception */ public function testLoggingError() { $parser = new TextParser(__DIR__ . '/templates'); $parser->setLogFile('noFile.log'); }
public function __construct($content = "") { parent::__construct($content); }
function testData_Text_TextParser() { $content = "My name is LuLu. I like meat! I very like meat! Recomended!"; $res = TextParser::ExtractKeywords($content, 1); $this->assertEqual($res[0], 'meat', "Invalid keyword extracting"); }
<?php require_once '../src/TextParserClass.php'; try { $parser = new TextParser('templates'); $parser->setLogFile('Logs/parser.log'); $textFiles = new DirectoryIterator('test_txt_files'); foreach ($textFiles as $txtObj) { if ($txtObj->getExtension() == 'txt') { echo '<h1>' . $txtObj->getFilename() . '</h1>'; $text = file_get_contents($txtObj->getPathname()); echo "<pre>"; print_r($parser->parseText($text)); echo "</pre>"; } } } catch (Exception $e) { echo '<h1>Caught exception:</h1>' . $e->getMessage(); }