pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] r3984 - trunk/pingus/src


From: grumbel at BerliOS
Subject: [Pingus-CVS] r3984 - trunk/pingus/src
Date: Thu, 26 Feb 2009 22:39:22 +0100

Author: grumbel
Date: 2009-02-26 22:39:22 +0100 (Thu, 26 Feb 2009)
New Revision: 3984

Modified:
   trunk/pingus/src/font.cpp
   trunk/pingus/src/string_format.cpp
   trunk/pingus/src/utf8.cpp
   trunk/pingus/src/utf8.hpp
Log:
Switched to a more C# like iterator

Modified: trunk/pingus/src/font.cpp
===================================================================
--- trunk/pingus/src/font.cpp   2009-02-26 21:22:13 UTC (rev 3983)
+++ trunk/pingus/src/font.cpp   2009-02-26 21:39:22 UTC (rev 3984)
@@ -109,7 +109,8 @@
     float dstx = float(x - offset.x);
     float dsty = float(y - offset.y);
     
-    for(UTF8::iterator i(text); !i.done(); ++i)
+    UTF8::iterator i(text);
+    while(i.next())
       {
         const uint32_t& unicode = *i;
 
@@ -144,7 +145,9 @@
   {
     float width = 0.0f;
     float last_width = 0;
-    for(UTF8::iterator i(text); !i.done(); ++i)
+    
+    UTF8::iterator i(text);
+    while(i.next())
       {
         const uint32_t& unicode = *i;
 
@@ -158,6 +161,7 @@
             width += get_width(unicode) + char_spacing;
           }
       }
+
     return std::max(width, last_width);
   }
 

Modified: trunk/pingus/src/string_format.cpp
===================================================================
--- trunk/pingus/src/string_format.cpp  2009-02-26 21:22:13 UTC (rev 3983)
+++ trunk/pingus/src/string_format.cpp  2009-02-26 21:39:22 UTC (rev 3984)
@@ -72,7 +72,8 @@
   float line_width = 0;
   std::ostringstream out;
   
-  for(UTF8::iterator it(text); !it.done(); ++it)
+  UTF8::iterator it(text);
+  while(it.next())
     {
       std::string word = UTF8::substr(beg, it+1);
       float word_width = font.get_width(word);

Modified: trunk/pingus/src/utf8.cpp
===================================================================
--- trunk/pingus/src/utf8.cpp   2009-02-26 21:22:13 UTC (rev 3983)
+++ trunk/pingus/src/utf8.cpp   2009-02-26 21:39:22 UTC (rev 3984)
@@ -187,52 +187,29 @@
 UTF8::iterator::iterator(const std::string& text_)
   : text(&text_),
     pos(0),
-    idx(0)
+    idx(0),
+    chr(INVALID_UTF8_SEQUENCE)
 {
-  try 
-    {
-      chr = decode_utf8(*text, pos);
-    } 
-  catch (std::exception) 
-    {
-      std::cout << "Malformed utf-8 sequence beginning with " << 
*((uint32_t*)(text->c_str() + pos)) << " found " << std::endl;
-      chr = INVALID_UTF8_SEQUENCE;
-    }
 }
 
 UTF8::iterator::iterator(const std::string& text_, const std::string::iterator 
it)
   : text(&text_),
     pos(it - text->begin()),
-    idx(pos)
+    idx(pos),
+    chr(INVALID_UTF8_SEQUENCE)
 {
-  try 
-    {
-      chr = decode_utf8(*text, pos);
-    } 
-  catch (std::exception) 
-    {
-      std::cout << "Malformed utf-8 sequence beginning with " << 
*((uint32_t*)(text->c_str() + pos)) << " found " << std::endl;
-      chr = INVALID_UTF8_SEQUENCE;
-    }
 }
 
-bool
-UTF8::iterator::done() const
-{
-  return pos > text->size();
-}
-
 UTF8::iterator
 UTF8::iterator::operator+(int n)
 {
   UTF8::iterator it = *this;
-  for(int i = 0; i < n; ++i)
-    ++it;
+  for(int i = 0; i < n && it.next(); ++i);
   return it;
 }
 
-UTF8::iterator&
-UTF8::iterator::operator++() 
+bool
+UTF8::iterator::next()
 {
   try 
     {
@@ -246,7 +223,7 @@
       ++pos;
     }
 
-  return *this;
+  return pos <= text->size();
 }
 
 uint32_t

Modified: trunk/pingus/src/utf8.hpp
===================================================================
--- trunk/pingus/src/utf8.hpp   2009-02-26 21:22:13 UTC (rev 3983)
+++ trunk/pingus/src/utf8.hpp   2009-02-26 21:39:22 UTC (rev 3984)
@@ -45,12 +45,13 @@
     iterator(const std::string& text);
     iterator(const std::string& text, std::string::iterator it);
 
-    bool done() const;
-    iterator& operator++();
+    bool next();
     iterator operator+(int n);
     uint32_t operator*() const;
     
+    /** Returns the starting position of the current character */
     std::string::size_type get_index() const { return idx; }
+
     const std::string& get_string() const { return *text; }
   };
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]