コード例 #1
0
ファイル: Parsed.php プロジェクト: Nycto/Round-Eights
 public function testSetIncludeUnquoted()
 {
     $list = new \r8\Quoter\Parsed();
     $this->assertTrue($list->getIncludeUnquoted());
     $this->assertSame($list, $list->setIncludeUnquoted(FALSE));
     $this->assertFalse($list->getIncludeUnquoted());
     $this->assertSame($list, $list->setIncludeUnquoted(TRUE));
     $this->assertTrue($list->getIncludeUnquoted());
 }
コード例 #2
0
ファイル: Quoter.php プロジェクト: Nycto/Round-Eights
 /**
  * Breaks a string up according the settings in this instance
  *
  * @param String $string The string to parse
  * @return Object Returns a \r8\Quoter\Parsed object
  */
 public function parse($string)
 {
     $string = (string) $string;
     $openQuotes = $this->getOpenQuotes();
     $result = new \r8\Quoter\Parsed();
     do {
         // Find the next open quote and it's offset
         list($openOffset, $openQuote) = self::findNext($string, $openQuotes, $this->escape);
         // If a quote couldn't be found, break out of the loop
         if ($openOffset === FALSE) {
             $result->addSection(new \r8\Quoter\Section\Unquoted($string));
             break;
         } else {
             if ($openOffset > 0) {
                 // Construct the unquoted section and add it to the result
                 $result->addSection(new \r8\Quoter\Section\Unquoted(substr($string, 0, $openOffset)));
             }
         }
         // Remove the unquoted section from the string
         $string = substr($string, $openOffset + strlen($openQuote));
         // Look for the close quote
         list($closeOffset, $closeQuote) = self::findNext($string, $this->getCloseQuotesFor($openQuote), $this->escape);
         if ($closeOffset === FALSE) {
             $quoted = $string;
         } else {
             $quoted = substr($string, 0, $closeOffset);
             $string = substr($string, $closeOffset + strlen($closeQuote));
         }
         // Construct the quoted section and add it to the result
         $result->addSection(new \r8\Quoter\Section\Quoted($quoted, $openQuote, $closeQuote));
     } while ($closeOffset !== FALSE && $string !== FALSE);
     return $result;
 }