public function testGetPrevNonWhitespace() { $this->assertSame(false, StringUtil::getPrevNonWhitespace(' ')); $this->assertSame(26, StringUtil::getPrevNonWhitespace('natural language processing')); $this->assertEquals(17, StringUtil::getPrevNonWhitespace('segmentasi kalimat')); $this->assertEquals(11, StringUtil::getPrevNonWhitespace('Saya belajar segmentasi kalimat.', 12)); // exclusive current position $this->assertEquals(4, StringUtil::getPrevNonWhitespace('bahasa', 5)); }
private function getLeftoverSpan($text, array $positions) { if ($positions[count($positions) - 1] != strlen($text) - 1) { $start = StringUtil::getNextNonWhitespace($text, $positions[count($positions) - 1]); $end = StringUtil::getPrevNonWhitespace($text); if ($start !== false && $end - $start > 0) { return new Span($start, $end + 1); } } }