Rename Delimiters to Splitter; add tests.

This commit is contained in:
Daniel Kraus
2017-08-27 22:32:32 +02:00
parent 3f2141e6c7
commit 1e27f47750
5 changed files with 43 additions and 33 deletions

View File

@ -72,7 +72,7 @@ class Linker {
$limitReached = false;
$newText = $text;
$delimiters = Delimiters::default( $this->config );
$splitter = Splitter::default( $this->config );
$targets = Targets::default( $title, $this->config );
// Iterate through the target page titles
@ -89,7 +89,7 @@ class Linker {
// Split the page content by non-linkable sections.
// Credits to inhan @ StackOverflow for suggesting preg_split.
// See http://stackoverflow.com/questions/10672286
$arr = $delimiters->split( $newText );
$arr = $splitter->split( $newText );
$count = 0;
// Cache the target title text for the regex callbacks
@ -113,7 +113,7 @@ class Linker {
if ( $this->config->smartMode && !$limitReached ) {
if ( $count > 0 ) {
// Split the text again because it was changed in the first pass.
$arr = $delimiters->split( $newText );
$arr = $splitter->split( $newText );
}
for ( $i = 0; $i < count( $arr ); $i+=2 ) {

View File

@ -1,6 +1,6 @@
<?php
/**
* The Delimiters class caches a regular expression that delimits text to be parsed.
* The Splitter class caches a regular expression that delimits text to be parsed.
*
* Copyright 2012-2017 Daniel Kraus <bovender@bovender.de> ('bovender')
*
@ -26,7 +26,7 @@ namespace LinkTitles;
/**
* Caches a regular expression that delimits text to be parsed.
*/
class Delimiters {
class Splitter {
/**
* The splitting expression that separates text to be parsed from text that
* must not be parsed.
@ -35,7 +35,7 @@ class Delimiters {
public $splitter;
/**
* The LinkTitles configuration for this Delimiters instance.
* The LinkTitles configuration for this Splitter instance.
* @var Config $config
*/
public $config;
@ -43,12 +43,12 @@ class Delimiters {
private static $instance;
/**
* Gets the Delimiters singleton; may build one with the given config or the
* Gets the Splitter singleton; may build one with the given config or the
* default config if none is given.
*
* If the instance was already created, it does not matter what Config this
* method is called with. To re-create an instance with a different Config,
* call Delimiters::invalidate() first.
* call Splitter::invalidate() first.
*
* @param Config|null $config LinkTitles configuration.
*/
@ -57,7 +57,7 @@ class Delimiters {
if ( $config === null ) {
$config = new Config();
}
self::$instance = new Delimiters( $config );
self::$instance = new Splitter( $config );
}
return self::$instance;
}
@ -73,7 +73,7 @@ class Delimiters {
protected function __construct( Config $config) {
$this->config = $config;
$this->buildDelimiters();
$this->buildSplitter();
}
/**
@ -92,7 +92,7 @@ class Delimiters {
* text that should be parsed from text that should not be
* parsed (e.g. inside existing links etc.)
*/
private function buildDelimiters() {
private function buildSplitter() {
if ( $this->config->skipTemplates )
{
// Use recursive regex to balance curly braces;