Browse Source

Update utf8 string iterator

Michael Ragazzon 6 years ago
parent
commit
9c930fa7f7

+ 3 - 3
Include/RmlUi/Core/StringUtilities.h

@@ -155,7 +155,7 @@ public:
 	inline const char* begin() const { return p_begin; }
 	inline const char* end() const { return p_end; }
 
-	inline size_t size() const { return p_end - p_begin; }
+	inline size_t size() const { return size_t(p_end - p_begin); }
 
 	explicit inline operator String() const {
 		return String(p_begin, p_end);
@@ -197,10 +197,10 @@ public:
 	bool operator!=(const StringIteratorU8& other) const { return !(*this == other); }
 
 	// Return a pointer to the current position.
-	inline const char* Get() const { return p; }
+	inline const char* get() const { return p; }
 
 	// Return offset from the beginning of string. Note: Can return negative if decremented.
-	std::ptrdiff_t Offset() const { return p - view.begin(); }
+	std::ptrdiff_t offset() const { return p - view.begin(); }
 
 private:
 	StringView view;

+ 2 - 2
Source/Controls/WidgetTextInput.cpp

@@ -155,7 +155,7 @@ void WidgetTextInput::SetMaxLength(int _max_length)
 				num_characters += 1;
 				if (num_characters > max_length)
 				{
-					i_erase = size_t(it.Offset());
+					i_erase = size_t(it.offset());
 					break;
 				}
 			}
@@ -853,7 +853,7 @@ int WidgetTextInput::CalculateCharacterIndex(int line_index, float position)
 	for(auto it = Core::StringIteratorU8(lines[line_index].content, 0, lines[line_index].content_length); it; )
 	{
 		++it;
-		int offset = (int)it.Offset();
+		int offset = (int)it.offset();
 
 		float line_width = (float) Core::ElementUtilities::GetStringWidth(text_element, lines[line_index].content.substr(0, offset));
 		if (line_width > position)

+ 1 - 1
Source/Core/DataBinding.cpp

@@ -157,7 +157,7 @@ bool DataViewAttribute::Update(const DataModel& model)
 	{
 		Variant* variant = element->GetAttribute(attribute_name);
 
-		if (!variant || (variant && *variant != value))
+		if (!variant || (variant && variant->Get<String>() != value))
 		{
 			element->SetAttribute(attribute_name, value);
 			result = true;

+ 3 - 3
Source/Core/StringUtilities.cpp

@@ -520,19 +520,19 @@ StringIteratorU8::StringIteratorU8(const String& string, size_t offset) : view(s
 StringIteratorU8::StringIteratorU8(const String& string, size_t offset, size_t count) : view(string, 0, offset + count), p(string.data() + offset)
 {}
 StringIteratorU8& StringIteratorU8::operator++() {
-	RMLUI_ASSERT(p != view.end());
+	RMLUI_ASSERT(p < view.end());
 	++p;
 	SeekForward();
 	return *this;
 }
 StringIteratorU8& StringIteratorU8::operator--() {
-	RMLUI_ASSERT(p - 1 != view.begin());
+	RMLUI_ASSERT(p >= view.begin());
 	--p;
 	SeekBack();
 	return *this;
 }
 inline void StringIteratorU8::SeekBack() {
-	p = StringUtilities::SeekBackwardUTF8(p, view.end());
+	p = StringUtilities::SeekBackwardUTF8(p, view.begin());
 }
 
 inline void StringIteratorU8::SeekForward() {