Changeset 428


Ignore:
Timestamp:
Oct 31, 2013 8:41:52 PM (11 years ago)
Author:
anonymous
Message:

Unicode regex fix required in multiple places; misc fixes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/1.1dev/lib/SpellCheck.inc.php

    r427 r428  
    199199    {
    200200        $corrections = array();
    201         // Split words on punctuation except apostrophes
     201        // Split words on punctuation except apostrophes (this regex is used in several places in this class).
    202202        // http://stackoverflow.com/questions/790596/split-a-text-into-single-words
    203         $words = preg_split("/((^\p{P}+)|(\p{P}*\s+\p{P}*)|([\p{Pd}–—-]+)|(\+|(\p{P}+$))/", $string);
     203        $words = preg_split("/((^\p{P}+)|(\p{P}*\s+\p{P}*)|[\p{Pd}—–-]+|(\p{P}+$))/", $string);
    204204        // Remove non-word elements.
    205205        $words = preg_grep('/\w+/', $words);
     
    235235    {
    236236        $errors = array();
    237         $words = preg_split('/([\W]+?)/', $string, -1, PREG_SPLIT_DELIM_CAPTURE);
     237        // Split words on punctuation except apostrophes (this regex is used in several places in this class).
     238        // http://stackoverflow.com/questions/790596/split-a-text-into-single-words
     239        $words = preg_split("/((^\p{P}+)|(\p{P}*\s+\p{P}*)|[\p{Pd}—–-]+|(\p{P}+$))/", $string);
    238240        // Remove non-word elements.
    239241        $check_words = preg_grep('/\w+/', $words);
     
    265267     */
    266268    function getStringHighlighted($string, $show_footnote=false)
    267     {
    268         $words = preg_split('/([\W]+?)/', $string, -1, PREG_SPLIT_DELIM_CAPTURE);
     269    {
     270        // Split words on punctuation except apostrophes (this regex is used in several places in this class).
     271        // http://stackoverflow.com/questions/790596/split-a-text-into-single-words
     272        $words = preg_split("/((^\p{P}+)|(\p{P}*\s+\p{P}*)|[\p{Pd}—–-]+|(\p{P}+$))/", $string);
    269273        $check_words = preg_grep('/\w+/', $words);
    270274        $cnt = 0;
     
    272276            foreach ($check_words as $i => $word) {
    273277                if (!$this->check($word)) {
    274                     $footnote = $show_footnote ? '<sup>' . ++$cnt . '</sup>' : '';
    275                     $words[$i] = $this->getParam('highlight_start') . $word . $this->getParam('highlight_end') . $footnote;
    276                 }
    277             }
    278         }
    279         return join('', $words);
     278                    $footnote = $show_footnote ? '<sup style="color:#999;">' . ++$cnt . '</sup>' : '';
     279                    $words[$i] = $this->getParam('highlight_start') . strip_tags($word) . $this->getParam('highlight_end') . $footnote;
     280                }
     281            }
     282        }
     283        return join(' ', $words);
    280284    }
    281285   
     
    296300        <?php
    297301       
    298         $form_words = $this->getStringSuggestions(getFormData($form_name));
     302        $form_words = array_values($this->getStringSuggestions(getFormData($form_name)));
    299303        if (is_array($form_words) && !empty($form_words)) {
    300304            ?><ol><?php
     
    302306                ?>
    303307                <li>
     308                <label style="color:#999;"><sub style="vertical-align:text-top;"><?php echo $i + 1; ?></sub></label>
    304309                <select name="spelling_suggestions[<?php echo $form_name ?>][<?php echo $i ?>]" onchange="document.forms[0].elements['spelling_corrections[<?php echo $form_name ?>][<?php echo $i ?>]'].value = this.value;">
    305310                <?php $original_word = array_shift($words); ?>
     
    352357    function applyFormCorrections($form_name)
    353358    {
    354         $form_words = preg_split('/([\W]+?)/', getFormData($form_name), -1, PREG_SPLIT_DELIM_CAPTURE);
     359        // Split words on punctuation except apostrophes (this regex is used in several places in this class).
     360        // http://stackoverflow.com/questions/790596/split-a-text-into-single-words
     361        $form_words = preg_split("/((^\p{P}+)|(\p{P}*\s+\p{P}*)|[\p{Pd}—–-]+|(\p{P}+$))/", getFormData($form_name));
    355362        $suggestions = getFormData('spelling_suggestions');
    356363        $corrections = getFormData('spelling_corrections');
Note: See TracChangeset for help on using the changeset viewer.