Reformat code

This commit is contained in:
Oleg Korshul
2024-07-26 11:40:01 +03:00
parent 0d84e22e79
commit 2920527898
3 changed files with 110 additions and 94 deletions

View File

@ -30,127 +30,141 @@
*
*/
#include "StringUTF32.h"
#include "StringExt.h"
using namespace std;
using namespace NSStringUtils;
CStringUTF32::CStringUTF32() {}
CStringUTF32::CStringUTF32(const CStringUTF32 &other): m_vec(other.m_vec) {}
CStringUTF32::CStringUTF32(const wchar_t *other) { *this = other; }
CStringUTF32::CStringUTF32(const wstring &other) { *this = other; }
CStringUTF32::CStringUTF32(const vector<uint32_t> &other): m_vec(other) {}
CStringUTF32::CStringUTF32()
{
}
CStringUTF32::CStringUTF32(const CStringUTF32& other) : m_vec(other.m_vec)
{
}
CStringUTF32::CStringUTF32(const wchar_t* other)
{
*this = other;
}
CStringUTF32::CStringUTF32(const wstring& other)
{
*this = other;
}
CStringUTF32::CStringUTF32(const vector<uint32_t>& other) : m_vec(other)
{
}
CStringUTF32::CStringUTF32(const uint32_t* data, const size_t& len)
{
m_vec.reserve(len);
for (size_t i = 0; i < len; ++i)
this->m_vec.push_back(data[i]);
for (size_t i = 0; i < len; ++i)
this->m_vec.push_back(data[i]);
}
CStringUTF32::~CStringUTF32() {}
CStringUTF32::~CStringUTF32()
{
}
bool CStringUTF32::empty() const
{
return this->m_vec.empty();
return this->m_vec.empty();
}
size_t CStringUTF32::length() const
{
return this->m_vec.size();
return this->m_vec.size();
}
wstring CStringUTF32::ToStdWString() const
{
if (0 == length())
return L"";
return NSStringExt::CConverter::GetUnicodeFromUTF32(&this->m_vec[0], static_cast<long>(this->length()));
if (0 == length())
return L"";
return NSStringExt::CConverter::GetUnicodeFromUTF32(&this->m_vec[0], static_cast<long>(this->length()));
}
bool CStringUTF32::operator == (const CStringUTF32 &right) const
bool CStringUTF32::operator==(const CStringUTF32& right) const
{
return this->m_vec == right.m_vec;
return this->m_vec == right.m_vec;
}
bool CStringUTF32::operator != (const CStringUTF32 &right) const
bool CStringUTF32::operator!=(const CStringUTF32& right) const
{
return !(this->m_vec == right.m_vec);
return !(this->m_vec == right.m_vec);
}
uint32_t& CStringUTF32::operator [] (size_t index)
uint32_t& CStringUTF32::operator[](size_t index)
{
return this->m_vec[index];
return this->m_vec[index];
}
CStringUTF32& CStringUTF32::operator = (const CStringUTF32 &right)
CStringUTF32& CStringUTF32::operator=(const CStringUTF32& right)
{
this->m_vec = right.m_vec;
return *this;
this->m_vec = right.m_vec;
return *this;
}
CStringUTF32& CStringUTF32::operator = (const wchar_t *right)
CStringUTF32& CStringUTF32::operator=(const wchar_t* right)
{
if (!right)
{
m_vec.clear();
return *this;
}
if (!right)
{
m_vec.clear();
return *this;
}
return (*this = std::wstring(right));
return (*this = std::wstring(right));
}
CStringUTF32& CStringUTF32::operator = (const wstring &right)
CStringUTF32& CStringUTF32::operator=(const wstring& right)
{
if (right.empty())
{
m_vec.clear();
return *this;
}
if (right.empty())
{
m_vec.clear();
return *this;
}
unsigned int utf32_len = 0;
unsigned int* utf32 = NSStringExt::CConverter::GetUtf32FromUnicode(right, utf32_len);
this->m_vec.clear();
this->m_vec.reserve(utf32_len);
for (size_t i = 0; i < utf32_len; ++i)
this->m_vec.push_back(utf32[i]);
unsigned int utf32_len = 0;
unsigned int* utf32 = NSStringExt::CConverter::GetUtf32FromUnicode(right, utf32_len);
this->m_vec.clear();
this->m_vec.reserve(utf32_len);
for (size_t i = 0; i < utf32_len; ++i)
this->m_vec.push_back(utf32[i]);
delete [] utf32;
return *this;
delete[] utf32;
return *this;
}
CStringUTF32& CStringUTF32::operator = (const std::vector<uint32_t> &right)
CStringUTF32& CStringUTF32::operator=(const std::vector<uint32_t>& right)
{
this->m_vec = right;
return *this;
this->m_vec = right;
return *this;
}
CStringUTF32 CStringUTF32::operator + (const CStringUTF32 &right) const
CStringUTF32 CStringUTF32::operator+(const CStringUTF32& right) const
{
CStringUTF32 result;
result.m_vec.reserve(this->length() + right.length());
result.m_vec.insert(result.m_vec.end(), m_vec.begin(), m_vec.end());
result.m_vec.insert(result.m_vec.end(), right.m_vec.begin(), right.m_vec.end());
return result;
CStringUTF32 result;
result.m_vec.reserve(this->length() + right.length());
result.m_vec.insert(result.m_vec.end(), m_vec.begin(), m_vec.end());
result.m_vec.insert(result.m_vec.end(), right.m_vec.begin(), right.m_vec.end());
return result;
}
CStringUTF32& CStringUTF32::operator += (const CStringUTF32 &right)
CStringUTF32& CStringUTF32::operator+=(const CStringUTF32& right)
{
m_vec.insert(m_vec.end(), right.m_vec.begin(), right.m_vec.end());
return *this;
m_vec.insert(m_vec.end(), right.m_vec.begin(), right.m_vec.end());
return *this;
}
CStringUTF32& CStringUTF32::operator += (const uint32_t& symbol)
CStringUTF32& CStringUTF32::operator+=(const uint32_t& symbol)
{
m_vec.push_back(symbol);
return *this;
m_vec.push_back(symbol);
return *this;
}
CStringUTF32 CStringUTF32::substr(size_t start, size_t count) const
{
CStringUTF32 result;
result.m_vec.reserve(count);
result.m_vec.insert(result.m_vec.end(), m_vec.begin() + start, m_vec.begin() + start + count);
return result;
CStringUTF32 result;
result.m_vec.reserve(count);
result.m_vec.insert(result.m_vec.end(), m_vec.begin() + start, m_vec.begin() + start + count);
return result;
}
const uint32_t& CStringUTF32::at(size_t index) const

View File

@ -32,48 +32,49 @@
#ifndef STRINGUTF32_HPP
#define STRINGUTF32_HPP
#include <stdint.h>
#include <string>
#include <vector>
#include <stdint.h>
#include "StringExt.h"
#include "../../Common/kernel_config.h"
namespace NSStringUtils
{
class KERNEL_DECL CStringUTF32
{
std::vector<uint32_t> m_vec;
public:
CStringUTF32();
CStringUTF32(const CStringUTF32 &other);
CStringUTF32(const wchar_t *other);
CStringUTF32(const std::wstring &other);
CStringUTF32(const std::vector<uint32_t> &other);
CStringUTF32(const uint32_t* data, const size_t& count);
virtual ~CStringUTF32();
class KERNEL_DECL CStringUTF32
{
std::vector<uint32_t> m_vec;
bool empty() const;
size_t length() const;
public:
CStringUTF32();
CStringUTF32(const CStringUTF32 &other);
CStringUTF32(const wchar_t *other);
CStringUTF32(const std::wstring &other);
CStringUTF32(const std::vector<uint32_t> &other);
CStringUTF32(const uint32_t *data, const size_t &count);
virtual ~CStringUTF32();
std::wstring ToStdWString() const;
bool empty() const;
size_t length() const;
bool operator == (const CStringUTF32 &right) const;
bool operator != (const CStringUTF32 &right) const;
uint32_t &operator [] (size_t index);
std::wstring ToStdWString() const;
CStringUTF32 &operator = (const CStringUTF32 &right);
CStringUTF32 &operator = (const wchar_t *right);
CStringUTF32 &operator = (const std::wstring &right);
CStringUTF32 &operator = (const std::vector<uint32_t> &right);
bool operator==(const CStringUTF32 &right) const;
bool operator!=(const CStringUTF32 &right) const;
uint32_t &operator[](size_t index);
CStringUTF32 operator + (const CStringUTF32 &right) const;
CStringUTF32 &operator += (const CStringUTF32 &right);
CStringUTF32 &operator += (const uint32_t& symbol);
CStringUTF32 &operator=(const CStringUTF32 &right);
CStringUTF32 &operator=(const wchar_t *right);
CStringUTF32 &operator=(const std::wstring &right);
CStringUTF32 &operator=(const std::vector<uint32_t> &right);
CStringUTF32 substr(size_t start, size_t count) const;
CStringUTF32 operator+(const CStringUTF32 &right) const;
CStringUTF32 &operator+=(const CStringUTF32 &right);
CStringUTF32 &operator+=(const uint32_t &symbol);
const uint32_t& at(size_t index) const;
uint32_t& at(size_t index);
};
}
CStringUTF32 substr(size_t start, size_t count) const;
const uint32_t &at(size_t index) const;
uint32_t &at(size_t index);
};
} // namespace NSStringUtils
#endif // STRINGUTF32_HPP

View File

@ -5,6 +5,7 @@
#include "../../../../DesktopEditor/graphics/structures.h"
#include "../../../../DesktopEditor/graphics/pro/Fonts.h"
#include "../../../../DesktopEditor/common/StringUTF32.h"
#include "../../../../DesktopEditor/common/StringExt.h"
namespace NSDocxRenderer
{