538 lines · 17.5 KB · C++
RawDownload
        std::lock_guard<std::mutex> lock{ _encoded_str_lock };         if (_encoded_str != nullptr)            return _encoded_str;         // If the string is ASCII then return the memory        if (_character_size == sizeof(char))        {            auto str = (_is_alloc) ? _mem.alloc : _mem.local;            if (_length_max <= _length)            {                auto tmp = alloc_memory<char>(_length + 1); // +1 for null                str = static_cast<uint8_t *>(std::memcpy(tmp, str, _length));            }             _encoded_str = reinterpret_cast<char *>(str);            assert(_encoded_str[_length] == '\0');            return _encoded_str;        }         const auto rune_str = (_is_alloc) ? reinterpret_cast<rune_t *>(_mem.alloc) : reinterpret_cast<rune_t *>(_mem.local);        const auto str_len = (_length * _character_size) + 1; // Plus 1 for a null terminator         auto encoded_str_local = alloc_memory<char>(str_len);         auto s = reinterpret_cast<uint8_t *>(encoded_str_local);        for (auto i = word_t{ 0 }; i < _length; ++i)        {            auto curr_rune = rune_str[i];            s = utf8::encode(curr_rune, s);        }         // Ensure the final value is null.        *s = 0;         _encoded_str = encoded_str_local;        return _encoded_str;    }}

Lines 501–538 of 538. Previous lines