Author: manolo
Date: 2010-12-15 09:38:39 -0800 (Wed, 15 Dec 2010)
New Revision: 8040
Log:
Homogenize use of re-encoding and transcoding (in favor of the latter).
Also, makes clear that the code is ready to deal with any encoding, not just 
fixed-length ones.

Modified:
   branches/branch-1.3/FL/Fl_Text_Buffer.H
   branches/branch-1.3/src/Fl_Text_Buffer.cxx
   branches/branch-1.3/test/editor.cxx

Modified: branches/branch-1.3/FL/Fl_Text_Buffer.H
===================================================================
--- branches/branch-1.3/FL/Fl_Text_Buffer.H     2010-12-15 16:58:08 UTC (rev 
8039)
+++ branches/branch-1.3/FL/Fl_Text_Buffer.H     2010-12-15 17:38:39 UTC (rev 
8040)
@@ -302,9 +302,9 @@
    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
+   UTF-8-transcoded 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.
+   \see input_file_was_transcoded and transcoding_warning_action.
    */
   int insertfile(const char *file, int pos, int buflen = 128*1024);
   
@@ -672,9 +672,9 @@
   int utf8_align(int) const;
   
   /**
-   \brief true iff the loaded file has been re-encoded to UTF-8
+   \brief true iff the loaded file has been transcoded to UTF-8
    */
-  int input_file_was_reencoded;
+  int input_file_was_transcoded;
 
   /** This message may be displayed using the fl_alert() function when a file
    which was not UTF-8 encoded is input.
@@ -685,10 +685,10 @@
    \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()
+   was transcoded 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.
+   displayed if this pointer is set to NULL. Use \ref input_file_was_transcoded
+   to be informed if file input required transcoding to UTF-8.
    */
   void (*transcoding_warning_action)(Fl_Text_Buffer*);
   

Modified: branches/branch-1.3/src/Fl_Text_Buffer.cxx
===================================================================
--- branches/branch-1.3/src/Fl_Text_Buffer.cxx  2010-12-15 16:58:08 UTC (rev 
8039)
+++ branches/branch-1.3/src/Fl_Text_Buffer.cxx  2010-12-15 17:38:39 UTC (rev 
8040)
@@ -133,7 +133,7 @@
   mPredeleteCbArgs = NULL;
   mCursorPosHint = 0;
   mCanUndo = 1;
-  input_file_was_reencoded = 0;
+  input_file_was_transcoded = 0;
   transcoding_warning_action = def_transcoding_warning_action;
 }
 
@@ -1520,8 +1520,8 @@
   return 0;
 }
 
-//#define FIXED_LENGTH_ENCODING // shows how to process any fixed-length 
encoding
-#ifdef FIXED_LENGTH_ENCODING 
+//#define EXAMPLE_ENCODING // shows how to process any encoding for which a 
decoding function exists
+#ifdef EXAMPLE_ENCODING 
 
 // returns the UCS equivalent of *p in CP1252 and advances p by 1
 unsigned cp1252toucs(char* &p)
@@ -1539,7 +1539,7 @@
   return (uc < 0x80 || uc >= 0xa0 ? uc : cp1252[uc - 0x80]);
 }
 
-// returns the UCS equivalent of *p in UTF-16 and advances p by 2
+// returns the UCS equivalent of *p in UTF-16 and advances p by 2 (or more for 
surrogates)
 unsigned utf16toucs(char* &p)
 {
   union {
@@ -1557,11 +1557,11 @@
 
 // filter that produces, from an input stream fed by reading from fp,
 // a UTF-8-encoded output stream written in buffer.
-// Input can be any fixed-length (e.g., 8-bit, UTF-16) encoding.
+// Input can be any (e.g., 8-bit, UTF-16) encoding.
 // Output is true UTF-8.
-// p_trf points to a function that transforms encoded byte(s) into UCS
+// p_trf points to a function that transforms encoded byte(s) into one UCS
 // and that increases the pointer by the adequate quantity
-static int fixed_length_input_filter(char *buffer, int buflen, 
+static int general_input_filter(char *buffer, int buflen, 
                                 char *line, int sline, char* &endline, 
                                 unsigned (*p_trf)(char* &),
                                 FILE *fp)
@@ -1590,7 +1590,7 @@
   endline -= (p - line);
   return q - buffer;
 }
-#endif // FIXED_LENGTH_ENCODING
+#endif // EXAMPLE_ENCODING
 
 /*
  filter that produces, from an input stream fed by reading from fp,
@@ -1645,7 +1645,7 @@
 }
 
 const char *Fl_Text_Buffer::file_encoding_warning_message = 
-"Displayed text contains the UTF-8 re-encoding\n"
+"Displayed text contains the UTF-8 transcoding\n"
 "of the input file which was not UTF-8 encoded.\n"
 "Some changes may have occurred.";
 
@@ -1663,19 +1663,19 @@
   char *buffer = new char[buflen + 1];  
   char *endline, line[100];
   int l;
-  input_file_was_reencoded = false;
+  input_file_was_transcoded = false;
   endline = line;
   while (true) {
-#ifdef FIXED_LENGTH_ENCODING
+#ifdef EXAMPLE_ENCODING
     // example of 16-bit encoding: UTF-16
-    l = fixed_length_input_filter(buffer, buflen, 
+    l = general_input_filter(buffer, buflen, 
                                  line, sizeof(line), endline, 
                                  utf16toucs, // use cp1252toucs to read 
CP1252-encoded files
                                  fp);
-    input_file_was_reencoded = true;
+    input_file_was_transcoded = true;
 #else
     l = utf8_input_filter(buffer, buflen, line, sizeof(line), endline, 
-                         fp, &input_file_was_reencoded);
+                         fp, &input_file_was_transcoded);
 #endif
     if (l == 0) break;
     buffer[l] = 0;
@@ -1685,7 +1685,7 @@
   int e = ferror(fp) ? 2 : 0;
   fclose(fp);
   delete[]buffer;
-  if ( (!e) && input_file_was_reencoded && transcoding_warning_action) {
+  if ( (!e) && input_file_was_transcoded && transcoding_warning_action) {
     transcoding_warning_action(this);
     }
   return e;

Modified: branches/branch-1.3/test/editor.cxx
===================================================================
--- branches/branch-1.3/test/editor.cxx 2010-12-15 16:58:08 UTC (rev 8039)
+++ branches/branch-1.3/test/editor.cxx 2010-12-15 17:38:39 UTC (rev 8040)
@@ -492,7 +492,7 @@
   int r;
   if (!insert) r = textbuf->loadfile(newfile);
   else r = textbuf->insertfile(newfile, ipos);
-  changed = changed || textbuf->input_file_was_reencoded;
+  changed = changed || textbuf->input_file_was_transcoded;
   if (r)
     fl_alert("Error reading from file \'%s\':\n%s.", newfile, strerror(errno));
   else

_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit

Reply via email to