Fix my strlcpy() adventure with a much simpler version of the code that should
also perform better for the usual case of inserting one char at a time. Using strpbrk() on non-terminated strings was probably also not too healthy. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36187 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
99e658c3e9
commit
846cb93278
@ -18,6 +18,7 @@
|
||||
#include <InterfaceDefs.h>
|
||||
#include <LayoutUtils.h>
|
||||
#include <Message.h>
|
||||
#include <String.h>
|
||||
#include <TextControl.h>
|
||||
#include <TextView.h>
|
||||
#include <Window.h>
|
||||
@ -204,28 +205,22 @@ void
|
||||
_BTextInput_::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] = ' ';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BTextView::InsertText(buffer ? buffer : inText, inLength, inOffset,
|
||||
// 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);
|
||||
}
|
||||
|
||||
TextControl()->InvokeNotify(TextControl()->ModificationMessage(),
|
||||
B_CONTROL_MODIFIED);
|
||||
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user