void CodeEditorComponent::getIteratorForPosition (int position, CodeDocument::Iterator& source)
{
    if (codeTokeniser == 0)
        return;

    for (int i = cachedIterators.size(); --i >= 0;)
    {
        CodeDocument::Iterator* t = cachedIterators.getUnchecked (i);
        if (t->getPosition() <= position)
        {
            source = *t;
            break;
        }
    }

    while (source.getPosition() < position)
    {
        const CodeDocument::Iterator original (source);
        codeTokeniser->readNextToken (source);

        if (source.getPosition() > position || source.isEOF())
        {
            source = original;
            break;
        }
    }
}
    static void createTokens (int startPosition, const String& lineText,
                              CodeDocument::Iterator& source,
                              CodeTokeniser* analyser,
                              OwnedArray <SyntaxToken>& newTokens)
    {
        CodeDocument::Iterator lastIterator (source);
        const int lineLength = lineText.length();

        for (;;)
        {
            int tokenType = analyser->readNextToken (source);
            int tokenStart = lastIterator.getPosition();
            int tokenEnd = source.getPosition();

            if (tokenEnd <= tokenStart)
                break;

            tokenEnd -= startPosition;

            if (tokenEnd > 0)
            {
                tokenStart -= startPosition;
                newTokens.add (new SyntaxToken (lineText.substring (jmax (0, tokenStart), tokenEnd),
                                                tokenType));

                if (tokenEnd >= lineLength)
                    break;
            }

            lastIterator = source;
        }

        source = lastIterator;
    }
int CtrlrMIDIBufferTokeniser::readNextToken (CodeDocument::Iterator &source)
{
	const juce_wchar c 	= source.peekNextChar();
	int result  		= CtrlrMIDIBufferTokeniser::tokenType_rawData;
	int pos 			= source.getPosition();
	int prefixHigh		= (tokenSet.prefixLen*3)-1;
	int suffixLow		= ((tokenSet.len) - (tokenSet.suffixLen*3));
	int suffixHigh		= tokenSet.len;
	int dataLow			= (tokenSet.dataOffset*3)-1;
	int dataHigh		= dataLow + ((tokenSet.dataLen*3));
	int nameLow			= (tokenSet.nameOffset*3)-1;
	int nameHigh		= nameLow + (tokenSet.nameLen*3);

	source.skipWhitespace();

	switch (c)
	{
		case 0:
			source.skip();
            return (result);
	}

	if (owner.getUnequalPosition().contains(pos))
	{
		source.skip();
		return (tokenType_mismatch);
	}

	if (pos >= 0 && pos < prefixHigh && prefixHigh>0)
	{
		source.skip();
		return (tokenType_prefix);
	}

	if (pos >= suffixLow && pos <= suffixHigh)
	{
		source.skip();
		return (tokenType_suffix);
	}

	if (pos >= dataLow && pos < dataHigh)
	{
		source.skip();
		return (tokenType_data);
	}

	if (pos >= nameLow && pos < nameHigh)
	{
		source.skip();
		return (tokenType_name);
	}
	source.skip();
	return result;
}