Changeset - r26745:baeac55e5810
[Not reviewed]
master
0 6 0
Rubidium - 23 months ago 2023-01-13 16:55:43
rubidium@openttd.org
Codechange: use smart pointers when creating StringIterators
6 files changed with 15 insertions and 18 deletions:
0 comments (0 inline, 0 general)
src/os/macosx/string_osx.cpp
Show inline comments
 
@@ -443,9 +443,9 @@ int MacOSStringCompare(const char *s1, c
 
	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>();
 
}
src/os/macosx/string_osx.h
Show inline comments
 
@@ -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();
 
};
 

	
 
/**
src/string.cpp
Show inline comments
 
@@ -765,9 +765,9 @@ int strnatcmp(const char *s1, const char
 

	
 
#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) */
 

	
src/string_base.h
Show inline comments
 
@@ -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() {}
 

	
src/textbuf.cpp
Show inline comments
 
@@ -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, uint1
 

	
 
Textbuf::~Textbuf()
 
{
 
	delete this->char_iter;
 
	free(this->buf);
 
}
 

	
src/textbuf_type.h
Show inline comments
 
@@ -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);
 

	
0 comments (0 inline, 0 general)