Browse Source

Fix some differences between old string and std::string

Michael Ragazzon 6 years ago
parent
commit
f77f6e9473

+ 7 - 4
Source/Controls/WidgetTextInput.cpp

@@ -433,7 +433,7 @@ bool WidgetTextInput::AddCharacter(Rocket::Core::word character)
 		DeleteSelection();
 
 	Core::WString value = Core::ToWideString(GetElement()->GetAttribute< Rocket::Core::String >("value", ""));
-	value.insert(GetCursorIndex(), Core::WString(1, character), 1);
+	value.insert(GetCursorIndex(), 1, character);
 
 	edit_index += 1;
 
@@ -964,10 +964,13 @@ void WidgetTextInput::GetLineSelection(Core::WString& pre_selection, Core::WStri
 		return;
 	}
 
+	int line_length = (int)line.size();
+	using namespace Rocket::Core::Math;
+
 	// Split the line up into its three parts, depending on the size and placement of the selection.
-	pre_selection = line.substr(0, Rocket::Core::Math::Max(0, selection_begin_index - line_begin));
-	selection = line.substr(Rocket::Core::Math::Max(0, selection_begin_index - line_begin), Rocket::Core::Math::Max(0, selection_length + Rocket::Core::Math::Min(0, selection_begin_index - line_begin)));
-	post_selection = line.substr(selection_begin_index + selection_length - line_begin);
+	pre_selection = line.substr(0, Max(0, selection_begin_index - line_begin));
+	selection = line.substr(Clamp(selection_begin_index - line_begin, 0, line_length), Max(0, selection_length + Min(0, selection_begin_index - line_begin)));
+	post_selection = line.substr(Clamp(selection_begin_index + selection_length - line_begin, 0, line_length));
 }
 
 void WidgetTextInput::SetKeyboardActive(bool active)

+ 2 - 1
Source/Core/BaseXMLParser.cpp

@@ -330,7 +330,8 @@ bool BaseXMLParser::ReadCDATA(const char* terminator)
 				String tag;
 				if (FindString((const unsigned char*) ">", tag))
 				{
-					String tag_name = StringUtilities::StripWhitespace(tag.substr(tag.find("/") + 1));
+					size_t slash_pos = tag.find('/');
+					String tag_name = StringUtilities::StripWhitespace(slash_pos == String::npos ? tag : tag.substr(slash_pos + 1));
 					if (ToLower(tag_name) == terminator)
 					{
 						data += cdata;

+ 5 - 2
Source/Core/PropertyParserColour.cpp

@@ -115,8 +115,11 @@ bool PropertyParserColour::ParseValue(Property& property, const String& value, c
 	{
 		StringList values;
 
-		int find = (int)value.find("(") + 1;
-		StringUtilities::ExpandString(values, value.substr(find, value.rfind(")") - find), ',');
+		size_t find = value.find('(');
+		if (find == String::npos)
+			return false;
+
+		StringUtilities::ExpandString(values, value.substr(find, value.rfind(')') - find), ',');
 
 		// Check if we're parsing an 'rgba' or 'rgb' colour declaration.
 		if (value.size() > 3 && value[3] == 'a')

+ 1 - 1
Source/Core/StyleSheetNode.cpp

@@ -524,7 +524,7 @@ StyleSheetNode* StyleSheetNode::CreateStructuralChild(const String& child_name)
 		else
 		{
 			// Alrighty; we've got an equation in the form of [[+/-]an][(+/-)b]. So, foist up, we split on 'n'.
-			size_t n_index = parameters.find("n");
+			size_t n_index = parameters.find('n');
 			if (n_index != String::npos)
 			{
 				// The equation is 0n + b. So a = 0, and we only have to parse b.

+ 1 - 1
Source/Core/StyleSheetParser.cpp

@@ -524,7 +524,7 @@ bool StyleSheetParser::ReadCharacter(char& buffer)
 					{
 						buffer = '/';
 						if (parse_buffer_pos == 0)
-							parse_buffer.insert(parse_buffer.begin() + parse_buffer_pos, '/');
+							parse_buffer.insert(parse_buffer_pos, 1, '/');
 						else
 							parse_buffer_pos--;
 						return true;

+ 1 - 1
Source/Core/SystemInterface.cpp

@@ -86,7 +86,7 @@ int SystemInterface::TranslateString(String& translated, const String& input)
 void SystemInterface::JoinPath(String& translated_path, const String& document_path, const String& path)
 {
 	// If the path is absolute, strip the leading / and return it.
-	if (path.substr(0, 1) == "/")
+	if (path.size() > 0 && path[0] == '/')
 	{
 		translated_path = path.substr(1);
 		return;