2015-04-01 19:36 GMT+02:00 <waddlesplash@xxxxxxxxx>:
+ BString contents;
+
+ BFile file(&ref, B_READ_WRITE);
+ off_t size;
+ file.GetSize(&size);
+ file.Seek(0, SEEK_SET);
+ char* buffer = new char[size];
+ file.Read(buffer, size);
+ if (fEncoding > 0) {
+ char* temp = strdup_to_utf8(fEncoding, buffer, size);
+ contents.SetTo(temp, size);
+ free(temp);
+ } else
+ contents.SetTo(buffer, size);
+ delete[] buffer;
+
+ int32 index = 0, lines = 1; // First line is 1 not 0
+ while (true) {
+ int32 newPos;
+ if (fCaseSensitive)
+ newPos = contents.FindFirst(fPattern, index);
+ else
+ newPos = contents.IFindFirst(fPattern, index);
+ if (newPos == B_ERROR)
+ break;
+
+ lines += _CountLines(contents, index, newPos);
+ BString linenoAndLine;
+ linenoAndLine.SetToFormat("%" B_PRId32 ":%s", lines,
_GetLine(contents, newPos).String());
+ message.AddString("text", linenoAndLine);
+
+ index = newPos + 1;
}