summaryrefslogtreecommitdiff
path: root/src/Fl_Text_Buffer.cxx
diff options
context:
space:
mode:
authorMatthias Melcher <fltk@matthiasm.com>2010-12-06 18:44:33 +0000
committerMatthias Melcher <fltk@matthiasm.com>2010-12-06 18:44:33 +0000
commitf18e8f4377bb18552abbd16931a6e3c9084498f5 (patch)
treeef5212d03f22b6e78b4d950b84d3136c4c802ca3 /src/Fl_Text_Buffer.cxx
parent1bac8a0ccae1f8993714e795d7da2e78245182d2 (diff)
Fixed Fl_Text_Editor::insert_file to load all text in a single chung to avoid UTF8 confusion and missmatched gaps.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@7966 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/Fl_Text_Buffer.cxx')
-rw-r--r--src/Fl_Text_Buffer.cxx16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/Fl_Text_Buffer.cxx b/src/Fl_Text_Buffer.cxx
index d1aea36f1..ac562aa6b 100644
--- a/src/Fl_Text_Buffer.cxx
+++ b/src/Fl_Text_Buffer.cxx
@@ -1516,19 +1516,21 @@ int Fl_Text_Buffer::findchar_backward(int startPos, unsigned int searchChar,
/*
Insert text from a file.
- Unicode safe. Inout must be correct UTF-8!
+ Unicode safe. Input must be correct UTF-8!
*/
-int Fl_Text_Buffer::insertfile(const char *file, int pos, int buflen)
+int Fl_Text_Buffer::insertfile(const char *file, int pos, int /*buflen*/)
{
FILE *fp;
if (!(fp = fl_fopen(file, "r")))
return 1;
- char *buffer = new char[buflen];
- for (int r; (r = fread(buffer, 1, buflen - 1, fp)) > 0; pos += r) {
- buffer[r] = (char) 0;
+ fseek(fp, 0, SEEK_END);
+ size_t filesize = ftell(fp);
+ fseek(fp, 0, SEEK_SET);
+ char *buffer = new char[filesize+1];
+ if (fread(buffer, 1, filesize, fp)==filesize) {
+ buffer[filesize] = (char) 0;
insert(pos, buffer);
}
-
int e = ferror(fp) ? 2 : 0;
fclose(fp);
delete[]buffer;
@@ -1562,7 +1564,7 @@ int Fl_Text_Buffer::outputfile(const char *file, int start, int end,
/*
Return the previous character position.
- Uncode safe.
+ Unicode safe.
*/
int Fl_Text_Buffer::prev_char_clipped(int pos) const
{