diff options
| author | Matthias Melcher <fltk@matthiasm.com> | 2009-09-23 21:32:23 +0000 |
|---|---|---|
| committer | Matthias Melcher <fltk@matthiasm.com> | 2009-09-23 21:32:23 +0000 |
| commit | b12b5134a30acc779fc1aaad0a27859180c5fe9c (patch) | |
| tree | 27443939ef6c6fd44feb2d32597ea555c14e30b8 /src | |
| parent | c153300e7f1c019294dd142fd545ede09f9a77f9 (diff) | |
File Chooser now also recognizes utf8 encoded text files. STR 2218.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@6899 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
| -rw-r--r-- | src/Fl_File_Chooser2.cxx | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/src/Fl_File_Chooser2.cxx b/src/Fl_File_Chooser2.cxx index 76314f4f5..5e5f1e3cf 100644 --- a/src/Fl_File_Chooser2.cxx +++ b/src/Fl_File_Chooser2.cxx @@ -1332,10 +1332,37 @@ Fl_File_Chooser::update_preview() window->cursor(FL_CURSOR_DEFAULT); Fl::check(); - // Scan the buffer for printable chars... - for (ptr = preview_text_; + // Scan the buffer for printable UTF8 chars... + for (ptr = preview_text_; *ptr; ptr++) { + uchar c = uchar(*ptr); + if ( (c&0x80)==0 ) { + if (!isprint(c&255) && !isspace(c&255)) break; + } else if ( (c&0xe0)==0xc0 ) { + if (ptr[1] && (ptr[1]&0xc0)!=0x80) break; + ptr++; + } else if ( (c&0xf0)==0xe0 ) { + if (ptr[1] && (ptr[1]&0xc0)!=0x80) break; + ptr++; + if (ptr[1] && (ptr[1]&0xc0)!=0x80) break; + ptr++; + } else if ( (c&0xf8)==0xf0 ) { + if (ptr[1] && (ptr[1]&0xc0)!=0x80) break; + ptr++; + if (ptr[1] && (ptr[1]&0xc0)!=0x80) break; + ptr++; + if (ptr[1] && (ptr[1]&0xc0)!=0x80) break; + ptr++; + } + } +// *ptr && (isprint(*ptr & 255) || isspace(*ptr & 255)); +// ptr ++); + + // Scan the buffer for printable characters in 8 bit + if (*ptr || ptr == preview_text_) { + for (ptr = preview_text_; *ptr && (isprint(*ptr & 255) || isspace(*ptr & 255)); ptr ++); + } if (*ptr || ptr == preview_text_) { // Non-printable file, just show a big ?... |
