<commit_before><?php
namespace XLSXExporter;

use SplFileObject;
use XLSXExporter\Utils\XmlConverter;

/**
 * Collection of Shared strings, this collection is a increase-only, cannot reduce or clean
 */
class SharedStrings implements \Countable
{
    protected $strings = [];

    /**
     * Add a string into the collection, return the index of the string
     * If the string already exists it will return the previous index
     * @param string $string
     * @return int
     */
    public function add($string)
    {
        // use the key instead of the content for faster access, it works like a bst
        if (array_key_exists($string, $this->strings)) {
            return $this->strings[$string];
        }
        $index = count($this->strings);
        $this->strings[$string] = $index;
        return $index;
    }

    /**
     * Write the XML content info to a file, the file name will be trucated
     * @return string Temporary file name
     */
    public function write()
    {
        $filename = tempnam(sys_get_temp_dir(), 'ws-');
        $file = new SplFileObject($filename, 'w');
        $this->writeTo($file);
        return $filename;
    }

    /**
     * Write the content to a SPlFileObject
     * @param SplFileObject $file
     */
    protected function writeTo(SplFileObject $file)
    {
        $count = count($this->strings);
        $file->fwrite(
            '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' . "\n"
            . '<sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"'
            . ' count="' . $count . '" uniqueCount="' . $count . '">'
        );
        // Not using the index, is not needed
        // do not use array_keys, it (could?) duplicate the memory usage
        foreach ($this->strings as $string => $index) {
            $file->fwrite('<si><t>' . XmlConverter::parse($string) . '</t></si>');
        }
        $file->fwrite('</sst>');
    }

    public function count($mode = 0)
    {
        return count($this->strings, $mode);
    }
}<commit_msg>implementation of \Countable does not receive arguments<commit_after><?php
namespace XLSXExporter;

use SplFileObject;
use XLSXExporter\Utils\XmlConverter;

/**
 * Collection of Shared strings, this collection is a increase-only, cannot reduce or clean
 */
class SharedStrings implements \Countable
{
    protected $strings = [];

    /**
     * Add a string into the collection, return the index of the string
     * If the string already exists it will return the previous index
     * @param string $string
     * @return int
     */
    public function add($string)
    {
        // use the key instead of the content for faster access, it works like a bst
        if (array_key_exists($string, $this->strings)) {
            return $this->strings[$string];
        }
        $index = count($this->strings);
        $this->strings[$string] = $index;
        return $index;
    }

    /**
     * Write the XML content info to a file, the file name will be trucated
     * @return string Temporary file name
     */
    public function write()
    {
        $filename = tempnam(sys_get_temp_dir(), 'ws-');
        $file = new SplFileObject($filename, 'w');
        $this->writeTo($file);
        return $filename;
    }

    /**
     * Write the content to a SPlFileObject
     * @param SplFileObject $file
     */
    protected function writeTo(SplFileObject $file)
    {
        $count = count($this->strings);
        $file->fwrite(
            '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' . "\n"
            . '<sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"'
            . ' count="' . $count . '" uniqueCount="' . $count . '">'
        );
        // Not using the index, is not needed
        // do not use array_keys, it (could?) duplicate the memory usage
        foreach ($this->strings as $string => $index) {
            $file->fwrite('<si><t>' . XmlConverter::parse($string) . '</t></si>');
        }
        $file->fwrite('</sst>');
    }

    public function count()
    {
        return count($this->strings);
    }
}
{'fraction_non_alphanumeric': 0.13684978123480798, 'fraction_numerical': 0.0036460865337870686, 'mean_word_length': 2.2999198075380916, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 2, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5310228', 'n_tokens_mistral': 1210, 'n_tokens_neox': 1166, 'n_words': 356}