コード例 #1
0
void ElementInfo::BuildPropertyRML(Core::String& property_rml, const Core::String& name, const Core::Property* property)
{
	Core::String property_value = property->ToString();
	RemoveTrailingZeroes(property_value);

	property_rml += Core::String(name.Length() + property_value.Length() + 32, "%s: <em>%s;</em><br />", name.CString(), property_value.CString());
}
コード例 #2
0
void ElementInfo::RemoveTrailingZeroes(Core::String& string)
{
	if (string.Empty())
	{
		return;
	}

	// First, check for a decimal point. No point, no chance of trailing zeroes!
	size_t decimal_point_position = string.Find(".");
	if (decimal_point_position != Core::String::npos)
	{
		// Ok, so now we start at the back of the string and find the first
		// numeral. If the character we find is a zero, then we start counting
		// back till we find something that isn't a zero or a decimal point -
		// and then remove all that we've counted.
		size_t last_zero = string.Length() - 1;
		while ((string[last_zero] < '0' || string[last_zero] > '9') && string[last_zero] != '.')
		{
			if (last_zero == 0)
			{
				return;
			}
			if (string[last_zero] == '.')
			{
				break;
			}
			last_zero--;
		}

		if (!(string[last_zero] == '0' || string[last_zero] == '.'))
		{
			return;
		}

		// Now find the first character that isn't a zero (unless we're just
		// chopping off the dangling decimal point)
		size_t first_zero = last_zero;
		if (string[last_zero] == '0')
		{
			while (first_zero > 0 && string[first_zero - 1] == '0')
			{
				first_zero--;
			}

			// Check for a preceeding decimal point - if it's all zeroes until the
			// decimal, then we should remove it too.
			if (string[first_zero - 1] == '.')
			{
				first_zero--;
			}
		}

		// Now remove everything between first_zero and last_zero, inclusive.
		if (last_zero > first_zero)
			string.Erase(first_zero, (last_zero - first_zero) + 1);
	}
}
コード例 #3
0
// Strips all \n and \r characters from the string.
void WidgetTextInputSingleLine::SanitiseValue(Core::String& value)
{
    Core::String new_value;
    for (Core::String::size_type i = 0; i < value.Length(); ++i)
    {
        switch (value[i])
        {
        case '\n':
        case '\r':
        case '\t':
            break;

        default:
            new_value += value[i];
        }
    }

    value = new_value;
}
コード例 #4
0
ファイル: common.cpp プロジェクト: Mikalai/punk_project_a
	const wxString Common::PunkStringToWxString(const Core::String& value) {
		return wxString((wchar_t*)value.Data(), value.Length());
	}
コード例 #5
0
void ElementInfo::UpdateSourceElement()
{
	// Set the title:
	Core::Element* title_content = GetElementById("title-content");
	if (title_content != NULL)
	{
		if (source_element != NULL)
			title_content->SetInnerRML(source_element->GetTagName());
		else
			title_content->SetInnerRML("Element Information");
	}

	// Set the attributes:
	Core::Element* attributes_content = GetElementById("attributes-content");
	if (attributes_content)
	{
		int index = 0;
		Core::String name;
		Core::String value;
		Core::String attributes;

		if (source_element != NULL)
		{
			while (source_element->IterateAttributes(index, name, value))
				attributes.Append(Core::String(name.Length() + value.Length() + 32, "%s: <em>%s</em><br />", name.CString(), value.CString()));
		}

		if (attributes.Empty())
		{
			while (attributes_content->HasChildNodes())
				attributes_content->RemoveChild(attributes_content->GetChild(0));
		}
		else
			attributes_content->SetInnerRML(attributes);
	}

	// Set the properties:
	Core::Element* properties_content = GetElementById("properties-content");
	if (properties_content)
	{
		Core::String properties;
		if (source_element != NULL)
			BuildElementPropertiesRML(properties, source_element, source_element);

		if (properties.Empty())
		{
			while (properties_content->HasChildNodes())
				properties_content->RemoveChild(properties_content->GetChild(0));
		}
		else
			properties_content->SetInnerRML(properties);
	}

	// Set the position:
	Core::Element* position_content = GetElementById("position-content");
	if (position_content)
	{
		// left, top, width, height.
		if (source_element != NULL)
		{
			Core::Vector2f element_offset = source_element->GetRelativeOffset(Core::Box::BORDER);
			Core::Vector2f element_size = source_element->GetBox().GetSize(Core::Box::BORDER);

			Core::String positions;
			positions.Append(Core::String(64, "left: <em>%.0fpx</em><br />", element_offset.x));
			positions.Append(Core::String(64, "top: <em>%.0fpx</em><br />", element_offset.y));
			positions.Append(Core::String(64, "width: <em>%.0fpx</em><br />", element_size.x));
			positions.Append(Core::String(64, "height: <em>%.0fpx</em><br />", element_size.y));

			position_content->SetInnerRML(positions);
		}
		else
		{
			while (position_content->HasChildNodes())
				position_content->RemoveChild(position_content->GetFirstChild());
		}
	}

	// Set the ancestors:
	Core::Element* ancestors_content = GetElementById("ancestors-content");
	if (ancestors_content)
	{
		Core::String ancestors;
		Core::Element* element_ancestor = NULL;
		if (source_element != NULL)
			element_ancestor = source_element->GetParentNode();

		int ancestor_depth = 1;
		while (element_ancestor)
		{
			Core::String ancestor_name = element_ancestor->GetTagName();
			const Core::String ancestor_id = element_ancestor->GetId();
			if (!ancestor_id.Empty())
			{
				ancestor_name += "#";
				ancestor_name += ancestor_id;
			}

			ancestors.Append(Core::String(ancestor_name.Length() + 32, "<p id=\"a %d\">%s</p>", ancestor_depth, ancestor_name.CString()));
			element_ancestor = element_ancestor->GetParentNode();
			ancestor_depth++;
		}

		if (ancestors.Empty())
		{
			while (ancestors_content->HasChildNodes())
				ancestors_content->RemoveChild(ancestors_content->GetFirstChild());
		}
		else
			ancestors_content->SetInnerRML(ancestors);
	}

	// Set the children:
	Core::Element* children_content = GetElementById("children-content");
	if (children_content)
	{
		Core::String children;
		if (source_element != NULL)
		{
			for (int i = 0; i < source_element->GetNumChildren(); i++)
			{
				Core::Element* child = source_element->GetChild(i);

				// If this is a debugger document, do not show it.
				if (IsDebuggerElement(child))
					continue;

				Core::String child_name = child->GetTagName();
				const Core::String child_id = child->GetId();
				if (!child_id.Empty())
				{
					child_name += "#";
					child_name += child_id;
				}

				children.Append(Core::String(child_name.Length() + 32, "<p id=\"c %d\">%s</p>", i, child_name.CString()));
			}
		}

		if (children.Empty())
		{
			while (children_content->HasChildNodes())
				children_content->RemoveChild(children_content->GetChild(0));
		}
		else
			children_content->SetInnerRML(children);
	}
}