From a26e66b548662dc307869b11f411b6ce019ab3ae Mon Sep 17 00:00:00 2001 From: stippi Date: Mon, 12 Apr 2010 16:57:03 +0000 Subject: [PATCH] One more round of simplification and fixing. git-svn-id: http://svn.haiku-os.org/webpositive/webkit/trunk@407 94f232f2-1747-11df-bad5-a5bfde151594 --- src/apps/webpositive/URLInputGroup.cpp | 30 +++++++++++--------------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/src/apps/webpositive/URLInputGroup.cpp b/src/apps/webpositive/URLInputGroup.cpp index 35a6130181..57c1d8baa7 100644 --- a/src/apps/webpositive/URLInputGroup.cpp +++ b/src/apps/webpositive/URLInputGroup.cpp @@ -317,25 +317,19 @@ void URLInputGroup::URLTextView::InsertText(const char* inText, int32 inLength, int32 inOffset, const text_run_array* inRuns) { - char* buffer = NULL; - - if (strpbrk(inText, "\r\n") && inLength <= 1024) { - buffer = (char*)malloc(inLength + 1); - - if (buffer) { - strlcpy(buffer, inText, inLength + 1); - - for (int32 i = 0; i < inLength; i++) { - if (buffer[i] == '\r' || buffer[i] == '\n') - buffer[i] = ' '; - } - } + // Filter all line breaks, note that inText is not terminated. + if (inLength == 1) { + if (*inText == '\n' || *inText == '\r') + BTextView::InsertText(" ", 1, inOffset, inRuns); + else + BTextView::InsertText(inText, 1, inOffset, inRuns); + } else { + BString filteredText(inText, inLength); + filteredText.ReplaceAll('\n', ' '); + filteredText.ReplaceAll('\r', ' '); + BTextView::InsertText(filteredText.String(), inLength, inOffset, + inRuns); } - - BTextView::InsertText(buffer ? buffer : inText, inLength, inOffset, - inRuns); - - free(buffer); }