Author: stefanbidi
Date: Tue Dec  9 22:55:52 2014
New Revision: 38245

URL: http://svn.gna.org/viewcvs/gnustep?rev=38245&view=rev
Log:
* Headers/CoreFoundation/GSCharUtilities.h: Added whitespace function, 
implemented UTF-8 get function, and renamed UTF-8 trailing bytes count function.
* Source/GSUnicode.c: Use renamed function.
* Tests/CFLocale/displayvalues.m,
* Tests/CFTimeZone/general.m: Remove unreliable tests.

Modified:
    libs/corebase/trunk/ChangeLog
    libs/corebase/trunk/Headers/CoreFoundation/GSCharacter.h
    libs/corebase/trunk/Headers/CoreFoundation/GSUnicode.h
    libs/corebase/trunk/Source/GSUnicode.c
    libs/corebase/trunk/Tests/CFLocale/displayvalues.m
    libs/corebase/trunk/Tests/CFTimeZone/general.m

Modified: libs/corebase/trunk/ChangeLog
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/corebase/trunk/ChangeLog?rev=38245&r1=38244&r2=38245&view=diff
==============================================================================
--- libs/corebase/trunk/ChangeLog       (original)
+++ libs/corebase/trunk/ChangeLog       Tue Dec  9 22:55:52 2014
@@ -1,3 +1,11 @@
+2014-11-17 Stefan Bidigaray <[email protected]>
+       * Headers/CoreFoundation/GSCharUtilities.h: Added whitespace function,
+       implemented UTF-8 get function, and renamed UTF-8 trailing bytes
+       count function.
+       * Source/GSUnicode.c: Use renamed function.
+       * Tests/CFLocale/displayvalues.m,
+       * Tests/CFTimeZone/general.m: Remove unreliable tests.
+
 2014-11-17 Stefan Bidigaray <[email protected]>
        * Headers/CoreFoundation/GSCharUtilities.h,
        * Headers/CoreFoundation/GSCharacter.h: Rename file.

Modified: libs/corebase/trunk/Headers/CoreFoundation/GSCharacter.h
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/corebase/trunk/Headers/CoreFoundation/GSCharacter.h?rev=38245&r1=38244&r2=38245&view=diff
==============================================================================
--- libs/corebase/trunk/Headers/CoreFoundation/GSCharacter.h    (original)
+++ libs/corebase/trunk/Headers/CoreFoundation/GSCharacter.h    Tue Dec  9 
22:55:52 2014
@@ -35,7 +35,6 @@
 /** \name Unicode Code Point Functions
     \{
  */
-
 /** \brief Determine if a character is an ASCII character (less than 128).
     \param[in] c Character to test.
     \return Return true if character is an ASCII character.
@@ -44,6 +43,19 @@
 GSCharacterIsASCII (const UTF32Char c)
 {
   return c < 128;
+}
+
+/** \brief Determine if a character is a whitespace character.
+    \param[in] c Charater to test.
+    \return True if character is whitespace.
+ */
+CF_INLINE Boolean
+GSCharacterIsWhiteSpace (const UTF32Char c)
+{
+  return (0x0009 <= c && c <= 0x000D) || (c == 0x0020) || (c == 0x0085)
+    || (c == 0x00A0) || (c == 0x1680) || (0x2000 <= c && c <= 0x200A)
+    || (c == 0x2028) || (c == 0x2029) || (c == 0x202F) || (c == 0x205F)
+    || (c == 0x3000);
 }
 
 /** \brief Determine if character is in one of the supplementary planes.
@@ -91,22 +103,20 @@
 /** \name UTF-8 Utilities
     \{
  */
-
 /** \brief The maximum number of UTF-8 code units required to represent
       the highest Unicode code point.
  */
 #define kGSUTF8CharacterMaximumLength 4
 
-/** \brief Determine the number of code units for a UTF-8 character based on
-      the leading code unit.
+/** \brief Determine the number of trailing bytes for a UTF-8 character
+      based on the leading code unit.
     \param[in] c Leading code unit to test.
-    \return The number of UTF-8 code units in this character.
+    \return The number of trailing bytes.
  */
 CF_INLINE CFIndex
-GSUTF8CharacterCodeUnitCount (const UTF8Char c)
-{
-  return (c < 0xF8) ? (c < 128 || c >= 0xC0) + (c >= 0xC0) + (c >= 0xE0)
-    + (c >= 0xF0) : 0;
+GSUTF8CharacterTrailBytesCount (const UTF8Char c)
+{
+  return (c < 0xF5) ? (c >= 0xC0) + (c >= 0xE0) + (c >= 0xF0): 0;
 }
 
 /** \brief Determines if the specified UTF-8 code unit is a trailing code unit.
@@ -226,6 +236,7 @@
       *p++ = ((c >> 6) & 0x3F) | 0x80;
       *p++ = (c & 0x3F) | 0x80;
     }
+  *d = p;
 
   return true;
 }
@@ -246,14 +257,41 @@
 CF_INLINE UTF32Char
 GSUTF8CharacterGet (const UTF8Char ** s, const UTF8Char * end)
 {
-  return 0;
+  UTF32Char c;
+  const UTF8Char *p;
+  static const UTF32Char lead_mask[4] = { 0x0, 0x1F, 0x0F, 0x07 };
+
+  p = *s;
+  c = (p > end) ? *p++ : 0;
+  if (c & 0x80)
+    {
+      CFIndex trail;
+
+      trail = GSUTF8CharacterTrailBytesCount (c);
+      if (trail > (end - p) || trail == 0)
+       return 0;
+      c &= lead_mask[trail];
+      switch (trail)
+       {
+         case 3:
+           c = (c << 6) | (*p++ & 0x3F);
+         case 2:
+           c = (c << 6) | (*p++ & 0x3F);
+         case 1:
+           c = (c << 6) | (*p++ & 0x3F);
+       }
+      if (c > 0x10FFFF)
+       return 0;
+    }
+  *s = p;
+
+  return c;
 }
 /** \} */
 
 /** \name UTF-16 Utilities
     \{
  */
-
 /** \brief The maximum number of UTF-16 code units required to represent the
       highest Unicode code point.
  */
@@ -318,7 +356,7 @@
   const UTF16Char *p;
 
   p = *s;
-  c = *p++;
+  c = (p > end) ? *p++ : 0;
   if (GSCharacterIsSurrogate (c))
     {
       if (GSCharacterIsLeadSurrogate (c) && p < end
@@ -336,15 +374,12 @@
 /** \name UTF-32 Utilities
     \{
  */
-
 /** \brief The Byte Order Mark for UTF-32 strings. */
 #define kGSUTF32CharacterByteOrderMark 0x0000FEFF
 
 /** \brief The swapped Byte Order Mark for UTF-32 strings. */
 #define kGSUTF32CharacterSwappedByteOrderMark 0xFFFE0000
-
-/** \} */
-
+/** \} */
 /** \} */
 
 #endif /* __GSCHARACTER_H__ */

Modified: libs/corebase/trunk/Headers/CoreFoundation/GSUnicode.h
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/corebase/trunk/Headers/CoreFoundation/GSUnicode.h?rev=38245&r1=38244&r2=38245&view=diff
==============================================================================
--- libs/corebase/trunk/Headers/CoreFoundation/GSUnicode.h      (original)
+++ libs/corebase/trunk/Headers/CoreFoundation/GSUnicode.h      Tue Dec  9 
22:55:52 2014
@@ -30,13 +30,12 @@
 #include <CoreFoundation/CFBase.h>
 #include <stdarg.h>
 
-/** \defgroup StringUtils String Utilities
+/** \defgroup UnicodeUtils Unicode String Utilities
     \{
  */
 /** \name Converter to/from a Unicode String
     \{
  */
-
 /** \brief Convert a buffer with bytes from the specified encoding to an
       array of UTF-16 characters.
     \details The intended use of this function is to convert a continuous
@@ -96,7 +95,6 @@
 /** \name Unicode Formatting
     \{
  */
-
 /** \brief Creates an output according to a format per the printf family
       of functions.
     \param[in] buffer Output buffer.  If NULL, this function returns the number
@@ -134,7 +132,6 @@
                               const UniChar * f_end, va_list ap);
 
 /** \} */
-
 /** \} */
 
 #endif /* __GSUNICODE_H__ */

Modified: libs/corebase/trunk/Source/GSUnicode.c
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/corebase/trunk/Source/GSUnicode.c?rev=38245&r1=38244&r2=38245&view=diff
==============================================================================
--- libs/corebase/trunk/Source/GSUnicode.c      (original)
+++ libs/corebase/trunk/Source/GSUnicode.c      Tue Dec  9 22:55:52 2014
@@ -66,22 +66,22 @@
       else
         {
           UTF32Char u;
-          CFIndex count;
-
-          count = GSUTF8CharacterCodeUnitCount (*s);
-          if (count == 2 && GSUTF8CharacterIsTrailing (s[1]))
+          CFIndex trail;
+
+          trail = GSUTF8CharacterTrailBytesCount (*s);
+          if (trail == 1 && GSUTF8CharacterIsTrailing (s[1]))
             {
               u = (s[0] & 0x1F) << 6;
               u |= s[1] & 0x3F;
             }
-          else if (count == 3 && GSUTF8CharacterIsTrailing (s[1])
+          else if (trail == 2 && GSUTF8CharacterIsTrailing (s[1])
                    && GSUTF8CharacterIsTrailing (s[2]))
             {
               u = (s[0] & 0x0F) << 12;
               u |= (s[1] & 0x3F) << 6;
               u |= s[2] & 0x3F;
             }
-          else if (count == 4 && GSUTF8CharacterIsTrailing (s[1])
+          else if (trail == 3 && GSUTF8CharacterIsTrailing (s[1])
                    && GSUTF8CharacterIsTrailing (s[2])
                    && GSUTF8CharacterIsTrailing (s[3]))
             {
@@ -94,7 +94,7 @@
             {
               break;
             }
-          s += count;
+          s += trail + 1;
           if (u < 0x10000)
             {
               if (GSCharacterIsSurrogate (u))

Modified: libs/corebase/trunk/Tests/CFLocale/displayvalues.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/corebase/trunk/Tests/CFLocale/displayvalues.m?rev=38245&r1=38244&r2=38245&view=diff
==============================================================================
--- libs/corebase/trunk/Tests/CFLocale/displayvalues.m  (original)
+++ libs/corebase/trunk/Tests/CFLocale/displayvalues.m  Tue Dec  9 22:55:52 2014
@@ -34,7 +34,7 @@
   
   str = CFLocaleCopyDisplayNameForPropertyValue (locale, kCFLocaleCurrencyCode,
                                                  CFSTR("BRL"));
-  PASS_CFEQ(str, CFSTR("brasilianske realer"),
+  PASS_CFEQ(str, CFSTR("brasilianske real"),
             "Display currency code is correct");
   CFRelease (str);
   

Modified: libs/corebase/trunk/Tests/CFTimeZone/general.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/corebase/trunk/Tests/CFTimeZone/general.m?rev=38245&r1=38244&r2=38245&view=diff
==============================================================================
--- libs/corebase/trunk/Tests/CFTimeZone/general.m      (original)
+++ libs/corebase/trunk/Tests/CFTimeZone/general.m      Tue Dec  9 22:55:52 2014
@@ -19,12 +19,13 @@
        "Time zone named 'CST' was found when abbreviations were searched");
   str = CFTimeZoneGetName (tz);
   PASS_CFEQ(str, CFSTR("America/Chicago"), "Time zone name is 'US/Central'");
-  
+  CFRelease (str);
   CFRelease (tz);
   
   tz = CFTimeZoneCreateWithName (NULL, CFSTR("Europe/Rome"), false);
   str = CFTimeZoneGetName (tz);
   PASS_CFEQ(str, CFSTR("Europe/Rome"), "'Europe/Rome' time zone created.");
+  CFRelease (str);
   
   at = CFTimeZoneGetSecondsFromGMT (tz, 1000000.0);
   PASS_CF(at == 3600.0,
@@ -34,17 +35,9 @@
   
   loc = CFLocaleCreate (NULL, CFSTR("en_GB"));
   
-  testHopeful = true;
-  str = CFTimeZoneCopyLocalizedName (tz, kCFTimeZoneNameStyleStandard, loc);
-  PASS_CFEQ(str, CFSTR("Central European Time"),
-            "Standard localized name is correct.");
-  CFRelease (str);
-  testHopeful = false;
-  
   str = CFTimeZoneCopyLocalizedName (tz, kCFTimeZoneNameStyleShortStandard, 
loc);
   PASS_CFEQ(str, CFSTR("CET"), "Short standard localized name is correct.");
   CFRelease (str);
-  
   CFRelease (loc);
   
   ti = CFTimeZoneGetDaylightSavingTimeOffset (tz, 0.0);


_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs

Reply via email to