You are here

protected function ContributorNames::checkAndSetLastNamePrefix in Bibliography Module 7.2

Check if the lastname has a prefix and set it

If the lastname has a prefix, it will either be captured as part of the lastname string, or as the middleName

Parameters

string $str:

Return value

array [0] is the prefix and [1] is the modified string

1 call to ContributorNames::checkAndSetLastNamePrefix()
ContributorNames::analyze in lib/msrc-authortool/src/Analyzer/ContributorNames.php
Analyze a string

File

lib/msrc-authortool/src/Analyzer/ContributorNames.php, line 207

Class

ContributorNames
Match Contributor Names with Predefined Regex

Namespace

Analyzer

Code

protected function checkAndSetLastNamePrefix($str) {
  $regex = "/\\b(von|van der|van den|van de|van|le|el|dos|de|de la)\\s[\\p{L}]/i";
  if (preg_match($regex, $str, $matches)) {

    //printf("\nFOUND %s: %s", $matches[1], $str);
    $prefix = $matches[1];
    $str = preg_replace("/" . $matches[1] . "/", '', $str, 1);

    //Fix double spaces caused by removal
    while (strpos($str, '  ')) {
      $str = str_replace('  ', ' ', $str);
    }

    //printf(" ... pre: %s ... ln: %s", $matches[1], $str);
  }
  else {
    $prefix = null;
  }
  return array(
    $prefix,
    $str,
  );
}