#include "tamiltest.h"
#include <QtCore/QTextBoundaryFinder>

TamilTest::TamilTest(QWidget *parent)
	: QMainWindow(parent)
{
	ui.setupUi(this);

	connect(ui.pushButtonProcess, SIGNAL(clicked()), SLOT(slot_PerformTamilTest()));
}

TamilTest::~TamilTest()
{

}

void TamilTest::slot_PerformTamilTest()
{
	// Store additional string and remove any unneeded end lines
	QString textString( ui.lineEditTamilString->text() );
	textString.remove("\r\n");

	// Parse input grapheme string
	QTextBoundaryFinder boundryFinder(QTextBoundaryFinder::Grapheme, textString);
	QStringList tamilChars;
	int prevIndex = 0;
	int nextIndex = boundryFinder.toNextBoundary();

	// Add all other elements
	while (nextIndex != -1)
	{
		// Append to grapheme list
		if (!tamilChars.contains(textString.mid(prevIndex, nextIndex - prevIndex)))
		{
			tamilChars.append(textString.mid(prevIndex, nextIndex - prevIndex));
		}
		// Correct indexes
		prevIndex = nextIndex;						// Store current index as previous
		nextIndex = boundryFinder.toNextBoundary();	// Get next index
	}

	// Display results
	ui.listWidgetTamliChars->clear();
	ui.listWidgetTamliChars->addItems(tamilChars);
}
