r4014 - trunk/birnet



Author: timj
Date: 2006-10-22 20:14:16 -0400 (Sun, 22 Oct 2006)
New Revision: 4014

Modified:
   trunk/birnet/ChangeLog
   trunk/birnet/birnetutf8.hh
Log:
Wed Oct 11 02:11:29 2006  Tim Janik  <timj gtk org>                                                                                                           
                                                                                                                                                              
        * birnetutf8.hh: added utf8_align() and utf8_aligned() to step back                                                                                   
        from the middle of an UTF-8 char.                                                                                                                     
                                                                                                                                                              



Modified: trunk/birnet/ChangeLog
===================================================================
--- trunk/birnet/ChangeLog	2006-10-22 23:10:32 UTC (rev 4013)
+++ trunk/birnet/ChangeLog	2006-10-23 00:14:16 UTC (rev 4014)
@@ -1,3 +1,8 @@
+Wed Oct 11 02:11:29 2006  Tim Janik  <timj gtk org>
+
+	* birnetutf8.hh: added utf8_align() and utf8_aligned() to step back
+	from the middle of an UTF-8 char.
+
 Sat Oct 21 19:02:47 2006  Tim Janik  <timj gtk org>
 
 	* birnettests.h (treport_generic): allow fixed portion of numbers

Modified: trunk/birnet/birnetutf8.hh
===================================================================
--- trunk/birnet/birnetutf8.hh	2006-10-22 23:10:32 UTC (rev 4013)
+++ trunk/birnet/birnetutf8.hh	2006-10-23 00:14:16 UTC (rev 4014)
@@ -89,6 +89,11 @@
                                          const char     *current);
 inline char*          utf8_find_prev    (const char     *start,
                                          char           *currrent);
+inline const char*    utf8_align        (const char     *start,
+                                         const char     *current);
+inline char*          utf8_align        (const char     *start,
+                                         char           *current);
+inline bool           utf8_aligned      (const char     *c);
 unichar               utf8_to_unichar   (const char     *str);
 int                   utf8_from_unichar (unichar         uc,
                                          char            str[8]);
@@ -179,7 +184,28 @@
   return const_cast<char*> (utf8_find_prev (start, const_cast<const char*> (current)));
 }
 
+inline const char*
+utf8_align (const char     *start,
+            const char     *current)
+{
+  while (current > start && (*current & 0xc0) == 0x80)
+    current--;
+  return current;
+}
 
+inline char*
+utf8_align (const char *start,
+            char       *current)
+{
+  return const_cast<char*> (utf8_align (start, const_cast<const char*> (current)));
+}
+
+inline bool
+utf8_aligned (const char *c)
+{
+  return (*c & 0xc0) == 0x80;
+}
+
 } // Birnet
 
 #endif /* __BIRNET_UTF8_HH__ */




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