You are here

function _fuzzysearch_char_count in Fuzzy Search 7

Same name and namespace in other branches
  1. 6 fuzzysearch.module \_fuzzysearch_char_count()

Helper to set character count of the found, clean word.

1 call to _fuzzysearch_char_count()
fuzzysearch_process_excerpt in ./fuzzysearch.module
Fuzzysearch process excerpt.

File

./fuzzysearch.module, line 482
Fuzzysearch module.

Code

function _fuzzysearch_char_count($text, $position) {
  $bytes = 0;

  // Count all the continuation bytes from the start until we have found
  // $start characters.
  $bytes = -1;
  $chars = -1;
  while ($bytes < $position) {
    $bytes++;
    $c = ord($text[$bytes]);
    if ($c < 0x80 || $c >= 0xc0) {
      $chars++;
    }
  }
  return $chars;
}