Ejemplo n.º 1
0
    public function testGetMarkersAndText()
    {
        $usfm = <<<'EOD'
\id GEN\c 10
EOD;
        $output = Filter_Usfm::getMarkersAndText($usfm);
        $this->assertEquals(array("\\id ", "GEN", "\\c ", "10"), $output);
        $usfm = <<<'EOD'
noise\id GEN\c 10
EOD;
        $output = Filter_Usfm::getMarkersAndText($usfm);
        $this->assertEquals(array("noise", "\\id ", "GEN", "\\c ", "10"), $output);
        $usfm = <<<'EOD'
\p\v 1 In \add the\add*
EOD;
        $output = Filter_Usfm::getMarkersAndText($usfm);
        $this->assertEquals(array("\\p", "\\v ", "1 In ", "\\add ", "the", "\\add*"), $output);
        $usfm = <<<'EOD'
\v 2 Text \add of the \add*1st\add second verse\add*.
EOD;
        $output = Filter_Usfm::getMarkersAndText($usfm);
        $this->assertEquals(array('\\v ', '2 Text ', '\\add ', 'of the ', '\\add*', '1st', '\\add ', 'second verse', '\\add*', '.'), $output);
        $usfm = <<<'EOD'
\p\v 1 In \+add the\+add*
EOD;
        $output = Filter_Usfm::getMarkersAndText($usfm);
        $this->assertEquals(array('\\p', '\\v ', '1 In ', '\\+add ', 'the', '\\+add*'), $output);
    }
Ejemplo n.º 2
0
 public function load($usfm)
 {
     // Clean up.
     $usfm = trim($usfm);
     $usfm .= "\n";
     // Separate it into markers and text.
     $markersAndText = Filter_Usfm::getMarkersAndText($usfm);
     // Load it into the object.
     $this->markersAndText = array();
     foreach ($markersAndText as $item) {
         $this->markersAndText[] = $item;
     }
     // Debug.
     //$this->debug = strpos ($usfm, "Footnote fk style") !== false;
 }
Ejemplo n.º 3
0
 /**
  * This function adds USFM code to the class.
  * $code: string or array of USFM code.
  */
 public function addUsfmCode($code)
 {
     // Get the USFM $code as a string.
     if (is_array($code)) {
         $code = implode("\n", $code);
     }
     $code .= "\n";
     // Sort the USFM $code out and separate it into markers and text.
     $markersAndText = Filter_Usfm::getMarkersAndText($code);
     foreach ($markersAndText as $item) {
         $this->usfmMarkersAndText[] = $item;
     }
 }
Ejemplo n.º 4
0
 public function check($usfm)
 {
     $this->newLineInUsfm($usfm);
     $this->forwardSlash($usfm);
     $this->usfmMarkersAndText = Filter_Usfm::getMarkersAndText($usfm);
     for ($this->usfmMarkersAndTextPointer = 0; $this->usfmMarkersAndTextPointer < count($this->usfmMarkersAndText); $this->usfmMarkersAndTextPointer++) {
         $this->usfmItem = $this->usfmMarkersAndText[$this->usfmMarkersAndTextPointer];
         if (Filter_Usfm::isUsfmMarker($this->usfmItem)) {
             // Get the current verse number.
             if ($this->usfmItem == '\\v ') {
                 $verseCode = Filter_Usfm::peekTextFollowingMarker($this->usfmMarkersAndText, $this->usfmMarkersAndTextPointer);
                 $this->verseNumber = Filter_Usfm::peekVerseNumber($verseCode);
             }
             $this->malformedVerseNumber();
             $this->markerInStylesheet();
             $this->malformedId();
             $this->widowBackSlash();
             $this->matchingEndmarker();
         } else {
         }
     }
 }
Ejemplo n.º 5
0
 public static function getVerseNumbers($usfm)
 {
     $verse_numbers = array(0);
     $markers_and_text = Filter_Usfm::getMarkersAndText($usfm);
     $extract_verse = false;
     foreach ($markers_and_text as $marker_or_text) {
         if ($extract_verse) {
             $verse_numbers[] = Filter_Numeric::integer_in_string($marker_or_text);
             $extract_verse = false;
         }
         if (substr($marker_or_text, 0, 2) == '\\v') {
             $extract_verse = true;
         }
     }
     return $verse_numbers;
 }