put common code for Insert() methods into DoInsertText(), this avoids an extra strlen() call

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18968 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini
2006-09-28 13:28:13 +00:00
parent 7d8ee43e80
commit 1e17db8ac6
+29 -28
View File
@@ -1083,16 +1083,17 @@ void
BTextView::Insert(const char *inText, const text_run_array *inRuns) BTextView::Insert(const char *inText, const text_run_array *inRuns)
{ {
if (inText != NULL) if (inText != NULL)
Insert(fSelStart, inText, strlen(inText), inRuns); DoInsertText(inText, strlen(inText), fSelStart, inRuns, NULL);
} }
void void
BTextView::Insert(const char *inText, int32 inLength, BTextView::Insert(const char *inText, int32 inLength, const text_run_array *inRuns)
const text_run_array *inRuns)
{ {
if (inText != NULL) if (inText != NULL && inLength > 0) {
Insert(fSelStart, inText, inLength, inRuns); int32 realLength = strlen(inText);
DoInsertText(inText, min_c(inLength, realLength), fSelStart, inRuns, NULL);
}
} }
@@ -1102,29 +1103,11 @@ BTextView::Insert(int32 startOffset, const char *inText, int32 inLength,
{ {
CALLED(); CALLED();
CancelInputMethod();
// do we really need to do anything? // do we really need to do anything?
if (inText == NULL || inLength < 1) if (inText != NULL && inLength > 0) {
return; int32 realLength = strlen(inText);
DoInsertText(inText, min_c(inLength, realLength), startOffset, inRuns, NULL);
int32 realLength = strlen(inText); }
if (inLength > realLength)
inLength = realLength;
if (startOffset > TextLength())
startOffset = TextLength();
// copy data into buffer
InsertText(inText, inLength, startOffset, inRuns);
// offset the caret/selection
int32 saveStart = fSelStart;
fSelStart += inLength;
fSelEnd += inLength;
// recalc line breaks and draw the text
Refresh(saveStart, fSelEnd, true, false);
} }
@@ -3503,7 +3486,25 @@ void
BTextView::DoInsertText(const char *inText, int32 inLength, int32 inOffset, BTextView::DoInsertText(const char *inText, int32 inLength, int32 inOffset,
const text_run_array *inRuns, _BTextChangeResult_ *outResult) const text_run_array *inRuns, _BTextChangeResult_ *outResult)
{ {
CALLED(); CancelInputMethod();
// Don't do any check, the public methods will have adjusted
// eventual bogus values...
int32 textLength = TextLength();
if (inOffset > textLength)
inOffset = textLength;
// copy data into buffer
InsertText(inText, inLength, inOffset, inRuns);
// offset the caret/selection
int32 saveStart = fSelStart;
fSelStart += inLength;
fSelEnd += inLength;
// recalc line breaks and draw the text
Refresh(saveStart, fSelEnd, true, false);
} }