Changeset 379 for trunk


Ignore:
Timestamp:
02/09/2010 12:57:43 AM (2 years ago)
Author:
ofer
Message:

First attempt at better number cutting

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/WordPress/plugin/transposh/core/parser.php

    r376 r379  
    261261     */ 
    262262    function is_number($page, $position) { 
    263         return strspn($page,'0123456789-+,.\\/',$position); 
     263        return strspn($page,'0123456789-+$%,.\\/',$position); 
    264264    } 
    265265 
     
    329329            } 
    330330            // Numbers also break, if they are followed by whitespace (or a sentence breaker) (don't break 42nd) // TODO: probably by breaking entities too... 
     331            // also prefixed by whitespace? 
    331332            elseif($num_len = $this->is_number($string,$pos)) { 
    332                 if ($this->is_white_space($string[$pos+$num_len]) ||  $this->is_sentence_breaker($string[$pos+$num_len],$string[$pos+$num_len+1],$string[$pos+$num_len+2])) { 
     333                // this is the case of B2 or B2, 
     334                if (($this->is_white_space($string[$pos-1]) || ($start == $pos) 
     335                        || ($this->is_sentence_breaker($string[$pos+$num_len-1],$string[$pos+$num_len],$string[$pos+$num_len+1]))) && 
     336                        ($this->is_white_space($string[$pos+$num_len]) ||  $this->is_sentence_breaker($string[$pos+$num_len],$string[$pos+$num_len+1],$string[$pos+$num_len+2]))) { 
     337                    // we will now compensate on the number followed by breaker case, if we need to 
     338                    if (!($this->is_white_space($string[$pos-1]) || ($start == $pos))) { 
     339                        if ($this->is_sentence_breaker($string[$pos+$num_len-1],$string[$pos+$num_len],$string[$pos+$num_len+1])) { 
     340                            $num_len--; //this makes the added number shorter by one, and the pos will be at a sentence breaker next so we don't have to compensate 
     341                        } 
     342                        $pos += $num_len; 
     343                        $num_len = 0; // we have already added this 
     344                    } 
    333345                    $this->tag_phrase($string,$start,$pos); 
    334346                    $start = $pos + $num_len + 1; 
Note: See TracChangeset for help on using the changeset viewer.