AttributedString and getNumAttributes


#1

If i construct an empty AttributedString, and append a line of text, how many attributes that object should have ? I’m getting two, identical ones, can i ask why? I’d like to iterate the object somehow:

AttributedString text;
text.append ("My Text", Font(10), Colours::black)

for (int i=0; i<text.getNumAttributes(); i++)
{
	const AttributedString::Attribute *a = text.getAttribute(i);

	if (a->getFont())
		textEditor->setFont (*a->getFont());

	if (a->getColour())
		textEditor->setColour (TextEditor::textColourId, *a->getColour());

	textEditor->insertTextAtCaret (text.getText().substring (a->range.getStart(), a->range.getEnd()));
}

#2

Well yes, it’s adding one attribute for the font, and another for the colour. Not incorrect, but I admit it would have been more efficient if it just used one attribute for both.


#3

Efficiency is not something i would ever say is a problem, i just wanted to somehow iterate the string and output it on screen depending on attributed parts of it. But the iteration will depend if i set the font, colour for each attribute etc. It was misleading that’s all, i can easily use an Array() of AttributedString objects or something similar.