Ejemplo n.º 1
0
void
TextGapBuffer::InsertText(BFile *file, int32 fileOffset, int32 inNumItems, int32 inAtIndex)
{
	off_t fileSize;

	if (file->GetSize(&fileSize) != B_OK
		|| !file->IsReadable())
		return;

	// Clamp the text length to the file size
	fileSize -= fileOffset;

	if (fileSize < inNumItems)
		inNumItems = fileSize;

	if (inNumItems < 1)
		return;

	inAtIndex = (inAtIndex > fItemCount) ? fItemCount : inAtIndex;
	inAtIndex = (inAtIndex < 0) ? 0 : inAtIndex;

	if (inAtIndex != fGapIndex)
		MoveGapTo(inAtIndex);

	if (fGapCount < inNumItems)
		SizeGapTo(inNumItems + kTextGapBufferBlockSize);

	// Finally, read the data and put it into the buffer
	if (file->ReadAt(fileOffset, fBuffer + fGapIndex, inNumItems) > 0) {
		fGapCount -= inNumItems;
		fGapIndex += inNumItems;
		fItemCount += inNumItems;
	}
}
Ejemplo n.º 2
0
const char *
TextGapBuffer::RealText()
{
	MoveGapTo(fItemCount);
	fBuffer[fItemCount] = '\0';
	
	return fBuffer;
}
Ejemplo n.º 3
0
const char *
TextGapBuffer::RealText()
{
	MoveGapTo(fItemCount);

	if (fGapCount == 0)
		SizeGapTo(kTextGapBufferBlockSize);

	fBuffer[fItemCount] = '\0';
	return fBuffer;
}
Ejemplo n.º 4
0
void
TextGapBuffer::RemoveRange(int32 start, int32 end)
{
	long inAtIndex = start;
	long inNumItems = end - start;

	if (inNumItems < 1)
		return;

	inAtIndex = (inAtIndex > fItemCount - 1) ? (fItemCount - 1) : inAtIndex;
	inAtIndex = (inAtIndex < 0) ? 0 : inAtIndex;

	MoveGapTo(inAtIndex);

	fGapCount += inNumItems;
	fItemCount -= inNumItems;

	if (fGapCount > kTextGapBufferBlockSize)
		SizeGapTo(kTextGapBufferBlockSize);
}
Ejemplo n.º 5
0
void
TextGapBuffer::InsertText(const char *inText, int32 inNumItems, int32 inAtIndex)
{
	if (inNumItems < 1)
		return;

	inAtIndex = (inAtIndex > fItemCount) ? fItemCount : inAtIndex;
	inAtIndex = (inAtIndex < 0) ? 0 : inAtIndex;

	if (inAtIndex != fGapIndex)
		MoveGapTo(inAtIndex);

	if (fGapCount < inNumItems)
		SizeGapTo(inNumItems + kTextGapBufferBlockSize);

	memcpy(fBuffer + fGapIndex, inText, inNumItems);

	fGapCount -= inNumItems;
	fGapIndex += inNumItems;
	fItemCount += inNumItems;
}