summaryrefslogtreecommitdiff
path: root/FL
diff options
context:
space:
mode:
authorManolo Gouy <Manolo>2010-12-10 19:24:28 +0000
committerManolo Gouy <Manolo>2010-12-10 19:24:28 +0000
commit85a03a76c9035635ea4a6f87500c475b0c9bf931 (patch)
tree4963bf57493e5c1fc2c56d87ce910fd8e9f9ade9 /FL
parent395f5a70aae1abbbaa2ce6be322ce197f134ef31 (diff)
Fix STR #2348. Files encoded with UTF-8 or CP1252 are accepted. Any non-UTF-8-encoded
data is interpreted according to CP1252 and transcoded to UTF-8. By default, a warning message is displayed when the input file was transcoded. This default behavior can be modified by changing a function pointer. A flag has been added to the Fl_Text_Buffer object that informs the caller if the input file was transcoded to UTF-8. The Fl_Text_Buffer.cxx file contains some preliminary code that could be used in the future to input other encodings provided they are fixed-length (e.g., all ISO-8859-* character sets, UTF-16). This code is not compiled at this point. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@8004 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'FL')
-rw-r--r--FL/Fl_Text_Buffer.H33
1 files changed, 28 insertions, 5 deletions
diff --git a/FL/Fl_Text_Buffer.H b/FL/Fl_Text_Buffer.H
index 3cc65da8d..1aaa4e792 100644
--- a/FL/Fl_Text_Buffer.H
+++ b/FL/Fl_Text_Buffer.H
@@ -300,20 +300,22 @@ public:
non-zero on error (strerror() contains reason). 1 indicates open
for read failed (no data loaded). 2 indicates error occurred
while reading data (data was partially loaded).
+ File can be UTF-8 or CP1252-encoded.
+ If the input file is not UTF-8-encoded, the Fl_Text_Buffer widget will contain
+ UTF-8-recoded data. By default, the message Fl_Text_Buffer::file_encoding_warning_message
+ will warn the user about this.
+ \see input_file_was_reencoded and transcoding_warning_action.
*/
int insertfile(const char *file, int pos, int buflen = 128*1024);
/**
- Appends the named file to the end of the buffer. Returns 0 on
- success, non-zero on error (strerror() contains reason). 1 indicates
- open for read failed (no data loaded). 2 indicates error occurred
- while reading data (data was partially loaded).
+ Appends the named file to the end of the buffer. See also insertfile().
*/
int appendfile(const char *file, int buflen = 128*1024)
{ return insertfile(file, length(), buflen); }
/**
- Loads a text file into the buffer
+ Loads a text file into the buffer. See also insertfile().
*/
int loadfile(const char *file, int buflen = 128*1024)
{ select(0, length()); remove_selection(); return appendfile(file, buflen); }
@@ -669,6 +671,27 @@ public:
*/
int utf8_align(int) const;
+ /**
+ \brief true iff the loaded file has been re-encoded to UTF-8
+ */
+ int input_file_was_reencoded;
+
+ /** This message may be displayed using the fl_alert() function when a file
+ which was not UTF-8 encoded is input.
+ */
+ static const char* file_encoding_warning_message;
+
+ /**
+ \brief Pointer to a function called after reading a non UTF-8 encoded file.
+
+ This function is called after reading a file if the file content
+ was re-encoded to UTF-8. Its default implementation calls fl_alert()
+ with the text of \ref file_encoding_warning_message. No warning message is
+ displayed if this pointer is set to NULL. Use \ref input_file_was_reencoded
+ to be programmatically informed if file input required re-encoding to UTF-8.
+ */
+ void (*transcoding_warning_action)(Fl_Text_Buffer*);
+
protected:
/**