Пример #1
0
int TextBuffer::Delete (int index, int count) {
    if (index < 0 || index > length) {
        return 0;
    } else if (count < 0) {
        return -Delete(index + count, -count);
    } else {
        count = Math::min(count, length - index);
        int oldlines = (count == 1)
            ? (text[index] == NEWLINE)
            : LinesBetween(index, index + count);
        if (lastindex > index + count) {
            lastindex -= count;
            lastline -= oldlines;
        } else if (lastindex >= index) {
            (void)LineNumber(index);
        }
        Memory::copy(
	    text + index + count, text + index, length - (index+count)
	);
        length -= count;
        Memory::zero(text + length, count);
        linecount -= oldlines;
        return count;
    }
}
Пример #2
0
const std::shared_ptr<TAstNode> TAstNodeForSentence::GetAstNode(TLexer* const lexer)
{
	auto token = lexer->GetToken();
	if (token->Type()!=TOKEN_TYPE::STRUCTURE_FOR)
	{
		throw TInterpreterException(TInterpreterException::WRONG_GRAMMAR, token->LineNumber());
	}

	std::shared_ptr<TAstNode> result(new TAstNodeForSentence(token));

	result->AddChild(TAstNodeAssignSentence::GetAssignException(lexer));

	AddToNode(lexer, token, result);
	AddStepNode(lexer, token, result);

	CheckLeftBrace(lexer);
	CheckLineBreak(lexer);

	AddSentenceNodes(lexer, result);

	int line = lexer->PeekToken()->LineNumber();
	CheckRightBrace(lexer);
	CheckEofEol(lexer);

	result->AddChild(TAstNodeNextSentence::GetAstNode(std::make_shared<TToken>(TOKEN_TYPE::STRUCTURE_NEXT, line)));

	return result;
}
Пример #3
0
void TextDisplay::Redraw (IntCoord l, IntCoord b, IntCoord r, IntCoord t) {
    if (canvas != nil) {
        int first = LineNumber(t);
        int last = LineNumber(b);
        for (int i = first; i <= last; ++i) {
            int begin = LineIndex(i, l, false);
            int end = LineIndex(i, r, false);
            TextLine* line = Line(i, false);
            if (line != nil) {
                line->Draw(this, i, begin, end);
            } else {
                IntCoord base = Base(i);
                IntCoord top = Top(i);
                painter->ClearRect(
		    canvas, l, Math::max(base, b), r, Math::min(top, t)
		);
            }
            if (caretline == i && caretindex >= begin && caretindex <= end) {
                ShowCaret();
            }
        }
    }
}