mirror of https://github.com/OpenTTD/OpenTTD
Codechange: use smart pointers when creating StringIterators
parent
b35c791d05
commit
b951332def
|
@ -443,9 +443,9 @@ int MacOSStringCompare(const char *s1, const char *s2)
|
|||
return this->utf16_to_utf8[this->cur_pos];
|
||||
}
|
||||
|
||||
/* static */ StringIterator *OSXStringIterator::Create()
|
||||
/* static */ std::unique_ptr<StringIterator> OSXStringIterator::Create()
|
||||
{
|
||||
if (!MacOSVersionIsAtLeast(10, 5, 0)) return nullptr;
|
||||
|
||||
return new OSXStringIterator();
|
||||
return std::make_unique<OSXStringIterator>();
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ public:
|
|||
size_t Next(IterType what) override;
|
||||
size_t Prev(IterType what) override;
|
||||
|
||||
static StringIterator *Create();
|
||||
static std::unique_ptr<StringIterator> Create();
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -765,9 +765,9 @@ int strnatcmp(const char *s1, const char *s2, bool ignore_garbage_at_front)
|
|||
|
||||
#ifdef WITH_UNISCRIBE
|
||||
|
||||
/* static */ StringIterator *StringIterator::Create()
|
||||
/* static */ std::unique_ptr<StringIterator> StringIterator::Create()
|
||||
{
|
||||
return new UniscribeStringIterator();
|
||||
return std::make_unique<UniscribeStringIterator>();
|
||||
}
|
||||
|
||||
#elif defined(WITH_ICU_I18N)
|
||||
|
@ -921,9 +921,9 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
/* static */ StringIterator *StringIterator::Create()
|
||||
/* static */ std::unique_ptr<StringIterator> StringIterator::Create()
|
||||
{
|
||||
return new IcuStringIterator();
|
||||
return std::make_unique<IcuStringIterator>();
|
||||
}
|
||||
|
||||
#else
|
||||
|
@ -1032,17 +1032,17 @@ public:
|
|||
};
|
||||
|
||||
#if defined(WITH_COCOA) && !defined(STRGEN) && !defined(SETTINGSGEN)
|
||||
/* static */ StringIterator *StringIterator::Create()
|
||||
/* static */ std::unique_ptr<StringIterator> StringIterator::Create()
|
||||
{
|
||||
StringIterator *i = OSXStringIterator::Create();
|
||||
std::unique_ptr<StringIterator> i = OSXStringIterator::Create();
|
||||
if (i != nullptr) return i;
|
||||
|
||||
return new DefaultStringIterator();
|
||||
return std::make_unique<DefaultStringIterator>();
|
||||
}
|
||||
#else
|
||||
/* static */ StringIterator *StringIterator::Create()
|
||||
/* static */ std::unique_ptr<StringIterator> StringIterator::Create()
|
||||
{
|
||||
return new DefaultStringIterator();
|
||||
return std::make_unique<DefaultStringIterator>();
|
||||
}
|
||||
#endif /* defined(WITH_COCOA) && !defined(STRGEN) && !defined(SETTINGSGEN) */
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ public:
|
|||
* Create a new iterator instance.
|
||||
* @return New iterator instance.
|
||||
*/
|
||||
static StringIterator *Create();
|
||||
static std::unique_ptr<StringIterator> Create();
|
||||
|
||||
virtual ~StringIterator() {}
|
||||
|
||||
|
|
|
@ -369,13 +369,11 @@ bool Textbuf::MovePos(uint16 keycode)
|
|||
* @param max_chars maximum size in chars, including terminating '\0'
|
||||
*/
|
||||
Textbuf::Textbuf(uint16 max_bytes, uint16 max_chars)
|
||||
: buf(MallocT<char>(max_bytes))
|
||||
: buf(MallocT<char>(max_bytes)), char_iter(StringIterator::Create())
|
||||
{
|
||||
assert(max_bytes != 0);
|
||||
assert(max_chars != 0);
|
||||
|
||||
this->char_iter = StringIterator::Create();
|
||||
|
||||
this->afilter = CS_ALPHANUMERAL;
|
||||
this->max_bytes = max_bytes;
|
||||
this->max_chars = max_chars == UINT16_MAX ? max_bytes : max_chars;
|
||||
|
@ -385,7 +383,6 @@ Textbuf::Textbuf(uint16 max_bytes, uint16 max_chars)
|
|||
|
||||
Textbuf::~Textbuf()
|
||||
{
|
||||
delete this->char_iter;
|
||||
free(this->buf);
|
||||
}
|
||||
|
||||
|
|
|
@ -67,7 +67,7 @@ struct Textbuf {
|
|||
void DiscardMarkedText(bool update = true);
|
||||
|
||||
private:
|
||||
StringIterator *char_iter;
|
||||
std::unique_ptr<StringIterator> char_iter;
|
||||
|
||||
bool CanDelChar(bool backspace);
|
||||
|
||||
|
|
Loading…
Reference in New Issue