[dasher] Fix SymbolStream UTF-8 character input function.



commit 86442bde36479fb0eb3aad8177055d779805f54c
Author: Alan Lawrence <acl33 inf phy cam ac uk>
Date:   Sat Feb 6 12:53:27 2010 +0100

    Fix SymbolStream UTF-8 character input function.

 ChangeLog                            |    4 ++++
 Src/DasherCore/Alphabet/Alphabet.cpp |   29 ++++++++++++++++-------------
 Src/DasherCore/Alphabet/Alphabet.h   |    2 +-
 3 files changed, 21 insertions(+), 14 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 1f2691a..a01f14e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2009-02-06  Alan Lawrence <acl33 inf phy cam ac uk>
+
+	* Fix SymbolStream UTF-8 character input function.
+
 2009-02-04  Patrick Welche <prlw1 cam ac uk>
 
 	* Fix bug #607775.
diff --git a/Src/DasherCore/Alphabet/Alphabet.cpp b/Src/DasherCore/Alphabet/Alphabet.cpp
index ef6db05..97f88bc 100644
--- a/Src/DasherCore/Alphabet/Alphabet.cpp
+++ b/Src/DasherCore/Alphabet/Alphabet.cpp
@@ -144,7 +144,7 @@ CAlphabet::utf8_length::utf8_length()
 
 CAlphabet::utf8_length CAlphabet::m_utf8_count_array;
 
-int CAlphabet::utf8_length::operator[](const int i) const
+int CAlphabet::utf8_length::operator[](const unsigned char i) const
 {
   return utf8_count_array[i];
 }
@@ -169,26 +169,29 @@ void CAlphabet::SymbolStream::readMore() {
 
 symbol CAlphabet::SymbolStream::next()
 {
-  if (pos + m_utf8_count_array.max_length > len && len==1024) {
+  int numChars;
+
+  for (;;) {
+    if (pos + m_utf8_count_array.max_length > len && len==1024) {
     //may need more bytes for next char; and input not yet exhausted.
 
-    if (pos) {
-      //shift remaining bytes to beginning
-      len-=pos; //len of them
-      memcpy(buf, &buf[pos], len);
-      pos=0;
+      if (pos) {
+        //shift remaining bytes to beginning
+        len-=pos; //len of them
+        memcpy(buf, &buf[pos], len);
+        pos=0;
+      }
+      readMore();
     }
-    readMore();
-  }
   //if still don't have any chars after attempting to read more...EOF!
-  if (pos==len) return -1;
-  int numChars;
-  for (;;) {
+    if (pos==len) return -1;
     numChars = m_utf8_count_array[buf[pos]];
     if (numChars != 0) break;
 #ifdef DEBUG
-    std::cerr << "Read invalid UTF-8 character 0x" << hex << buf[pos] << dec << std::endl;
+    std::cerr << "Read invalid UTF-8 character 0x" << hex << buf[pos]
+              << dec << std::endl;
 #endif
+    ++pos;
   }
   if (numChars == 1)
     return map.GetSingleChar(buf[pos++]);
diff --git a/Src/DasherCore/Alphabet/Alphabet.h b/Src/DasherCore/Alphabet/Alphabet.h
index 3bc0fe0..ba31c45 100644
--- a/Src/DasherCore/Alphabet/Alphabet.h
+++ b/Src/DasherCore/Alphabet/Alphabet.h
@@ -177,7 +177,7 @@ namespace Dasher {
       {
         public:
           utf8_length();
-          int operator[](const int) const;
+          int operator[](const unsigned char) const;
           int max_length;
         private:
           int utf8_count_array[0x100];



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]