CoreFiles by mySites.guru
Zh.php87 lines, 2,150 bytes, from Joomla_4.3.3-Stable-Full_Package.zip
Raw History Compare with 4.3.2
md5
ede64168ed91b8e3df495b094b51f8a9
sha1
6770b71841a7b5cec76ab9b11ad45d6cb4c9076c
sha256
7360d8c25de9dff8ac0c524b1749955b70a1c2b79910c69fb8fcd5a9da67e94c
<?php

/**
 * @package     Joomla.Administrator
 * @subpackage  com_finder
 *
 * @copyright   (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

namespace Joomla\Component\Finder\Administrator\Indexer\Language;

use Joomla\Component\Finder\Administrator\Indexer\Language;
use Joomla\String\StringHelper;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
 * Chinese (simplified) language support class for the Finder indexer package.
 *
 * @since  4.0.0
 */
class Zh extends Language
{
    /**
     * Language locale of the class
     *
     * @var    string
     * @since  4.0.0
     */
    public $language = 'zh';

    /**
     * Spacer between terms
     *
     * @var    string
     * @since  4.0.0
     */
    public $spacer = '';

    /**
     * Method to construct the language object.
     *
     * @since   4.0.0
     */
    public function __construct($locale = null)
    {
        // Override parent constructor since we don't need to load an external stemmer
    }

    /**
     * Method to tokenise a text string.
     *
     * @param   string  $input  The input to tokenise.
     *
     * @return  array  An array of term strings.
     *
     * @since   4.0.0
     */
    public function tokenise($input)
    {
        $terms = parent::tokenise($input);

        // Iterate through the terms and test if they contain Chinese.
        for ($i = 0, $n = count($terms); $i < $n; $i++) {
            $charMatches = [];
            $charCount   = preg_match_all('#[\p{Han}]#mui', $terms[$i], $charMatches);

            // Split apart any groups of Chinese characters.
            for ($j = 0; $j < $charCount; $j++) {
                $tSplit = StringHelper::str_ireplace($charMatches[0][$j], '', $terms[$i], false);

                if (!empty($tSplit)) {
                    $terms[$i] = $tSplit;
                } else {
                    unset($terms[$i]);
                }

                $terms[] = $charMatches[0][$j];
            }
        }

        return $terms;
    }
}

The same content is in 20 releases, Joomla 4.3.0-beta1 to 5.0.0-alpha3. See them all, or every version of this file.