[haiku-commits] r37414 - in haiku/branches/developer/zooey/posix-locale: headers/posix headers/private/libroot/locale src/system/libroot src/system/libroot/posix/glibc src/system/libroot/posix/locale

  • From: zooey@xxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 6 Jul 2010 23:31:04 +0200 (CEST)

Author: zooey
Date: 2010-07-06 23:31:04 +0200 (Tue, 06 Jul 2010)
New Revision: 37414
Changeset: http://dev.haiku-os.org/changeset/37414/haiku

Added:
   
haiku/branches/developer/zooey/posix-locale/src/system/libroot/posix/locale/wctype.cpp
Removed:
   
haiku/branches/developer/zooey/posix-locale/src/system/libroot/posix/glibc/wctype/
Modified:
   haiku/branches/developer/zooey/posix-locale/headers/posix/wchar.h
   haiku/branches/developer/zooey/posix-locale/headers/posix/wctype.h
   
haiku/branches/developer/zooey/posix-locale/headers/private/libroot/locale/ICUCtypeData.h
   
haiku/branches/developer/zooey/posix-locale/headers/private/libroot/locale/ICULocaleBackend.h
   
haiku/branches/developer/zooey/posix-locale/headers/private/libroot/locale/LocaleBackend.h
   haiku/branches/developer/zooey/posix-locale/src/system/libroot/Jamfile
   
haiku/branches/developer/zooey/posix-locale/src/system/libroot/posix/glibc/Jamfile
   
haiku/branches/developer/zooey/posix-locale/src/system/libroot/posix/locale/ICUCtypeData.cpp
   
haiku/branches/developer/zooey/posix-locale/src/system/libroot/posix/locale/ICULocaleBackend.cpp
   
haiku/branches/developer/zooey/posix-locale/src/system/libroot/posix/locale/Jamfile
Log:
Implemented wctype functionality and dropped the glibc implementations.
* added implementations for all isw... functions that either delegate
  to the ICU backend or to the respective isctype function if no backend
  has been loaded (i.e. the POSIX locale)
* added IsWCType() and ToWCTrans() methods to ICU backend
* changed definition of wctrans_t from const int* to int (no idea why
  it was defined that way, but using int makes it compatible with isctype)
* added comment to wchar.h about how Haiku handles (well, is going to handle) 
  wide character types - they will always contain strings in UTF32 encoding
* dropped the whole wctype folder of glibc


Modified: haiku/branches/developer/zooey/posix-locale/headers/posix/wchar.h
===================================================================
--- haiku/branches/developer/zooey/posix-locale/headers/posix/wchar.h   
2010-07-06 20:52:10 UTC (rev 37413)
+++ haiku/branches/developer/zooey/posix-locale/headers/posix/wchar.h   
2010-07-06 21:31:04 UTC (rev 37414)
@@ -36,7 +36,13 @@
 #define WCHAR_MIN      0x00000000UL
 #define WCHAR_MAX      0x7FFFFFFFUL
 
+/*
+ * Haiku is always using UTF32 in wchars, other encodings can be handled
+ * by converting to/from wchar by means of mbsrtowcs() or wcsrtombs().
+ * TODO: define __STDC_ISO_10646__ accordingly in our compilers.
+ */
 
+
 #ifdef __cplusplus
 extern "C" {
 #endif

Modified: haiku/branches/developer/zooey/posix-locale/headers/posix/wctype.h
===================================================================
--- haiku/branches/developer/zooey/posix-locale/headers/posix/wctype.h  
2010-07-06 20:52:10 UTC (rev 37413)
+++ haiku/branches/developer/zooey/posix-locale/headers/posix/wctype.h  
2010-07-06 21:31:04 UTC (rev 37414)
@@ -8,7 +8,7 @@
 
 #include <wchar.h>
 
-typedef const int *wctrans_t;
+typedef int wctrans_t;
 
 #ifdef __cplusplus
 extern "C" {

Modified: 
haiku/branches/developer/zooey/posix-locale/headers/private/libroot/locale/ICUCtypeData.h
===================================================================
--- 
haiku/branches/developer/zooey/posix-locale/headers/private/libroot/locale/ICUCtypeData.h
   2010-07-06 20:52:10 UTC (rev 37413)
+++ 
haiku/branches/developer/zooey/posix-locale/headers/private/libroot/locale/ICUCtypeData.h
   2010-07-06 21:31:04 UTC (rev 37414)
@@ -23,6 +23,9 @@
                                                                        const 
char* posixLocaleName);
        virtual status_t                        SetToPosix();
 
+                       int                                     IsWCType(wint_t 
wc, wctype_t charClass);
+                       wint_t                          ToWCTrans(wint_t wc, 
wctrans_t charClass);
+
                        void                            InitializeDataBridge(
                                                                        
LocaleCtypeDataBridge* dataBridge);
 };

Modified: 
haiku/branches/developer/zooey/posix-locale/headers/private/libroot/locale/ICULocaleBackend.h
===================================================================
--- 
haiku/branches/developer/zooey/posix-locale/headers/private/libroot/locale/ICULocaleBackend.h
       2010-07-06 20:52:10 UTC (rev 37413)
+++ 
haiku/branches/developer/zooey/posix-locale/headers/private/libroot/locale/ICULocaleBackend.h
       2010-07-06 21:31:04 UTC (rev 37414)
@@ -32,6 +32,9 @@
        virtual const struct lconv*     LocaleConv();
        virtual const struct lc_time_t* LCTimeInfo();
 
+       virtual int                                     IsWCType(wint_t wc, 
wctype_t charClass);
+       virtual wint_t                          ToWCTrans(wint_t wc, wctrans_t 
charClass);
+
        virtual void                            InitializeDataBridge(
                                                                        
LocaleDataBridge* dataBridge);
 

Modified: 
haiku/branches/developer/zooey/posix-locale/headers/private/libroot/locale/LocaleBackend.h
===================================================================
--- 
haiku/branches/developer/zooey/posix-locale/headers/private/libroot/locale/LocaleBackend.h
  2010-07-06 20:52:10 UTC (rev 37413)
+++ 
haiku/branches/developer/zooey/posix-locale/headers/private/libroot/locale/LocaleBackend.h
  2010-07-06 21:31:04 UTC (rev 37414)
@@ -8,7 +8,9 @@
 
 #include <SupportDefs.h>
 
+#include <wctype.h>
 
+
 struct lconv;
 struct lc_time_t;
 
@@ -37,6 +39,9 @@
        virtual const struct lconv*     LocaleConv() = 0;
        virtual const struct lc_time_t* LCTimeInfo() = 0;
 
+       virtual int                                     IsWCType(wint_t wc, 
wctype_t charClass) = 0;
+       virtual wint_t                          ToWCTrans(wint_t wc, wctrans_t 
charClass) = 0;
+
        virtual void                            InitializeDataBridge(
                                                                        
LocaleDataBridge* dataBridge) = 0;
 

Modified: haiku/branches/developer/zooey/posix-locale/src/system/libroot/Jamfile
===================================================================
--- haiku/branches/developer/zooey/posix-locale/src/system/libroot/Jamfile      
2010-07-06 20:52:10 UTC (rev 37413)
+++ haiku/branches/developer/zooey/posix-locale/src/system/libroot/Jamfile      
2010-07-06 21:31:04 UTC (rev 37414)
@@ -30,7 +30,6 @@
        posix_gnu_stdlib.o
        posix_gnu_string.o
        posix_gnu_wcsmbs.o
-       posix_gnu_wctype.o
        posix_stdlib.o
        posix_string.o
        posix_string_arch_$(TARGET_ARCH).o

Modified: 
haiku/branches/developer/zooey/posix-locale/src/system/libroot/posix/glibc/Jamfile
===================================================================
--- 
haiku/branches/developer/zooey/posix-locale/src/system/libroot/posix/glibc/Jamfile
  2010-07-06 20:52:10 UTC (rev 37413)
+++ 
haiku/branches/developer/zooey/posix-locale/src/system/libroot/posix/glibc/Jamfile
  2010-07-06 21:31:04 UTC (rev 37414)
@@ -12,4 +12,3 @@
 SubInclude HAIKU_TOP src system libroot posix glibc stdlib ;
 SubInclude HAIKU_TOP src system libroot posix glibc string ;
 SubInclude HAIKU_TOP src system libroot posix glibc wcsmbs ;
-SubInclude HAIKU_TOP src system libroot posix glibc wctype ;

Modified: 
haiku/branches/developer/zooey/posix-locale/src/system/libroot/posix/locale/ICUCtypeData.cpp
===================================================================
--- 
haiku/branches/developer/zooey/posix-locale/src/system/libroot/posix/locale/ICUCtypeData.cpp
        2010-07-06 20:52:10 UTC (rev 37413)
+++ 
haiku/branches/developer/zooey/posix-locale/src/system/libroot/posix/locale/ICUCtypeData.cpp
        2010-07-06 21:31:04 UTC (rev 37414)
@@ -126,4 +126,52 @@
 }
 
 
+int
+ICUCtypeData::IsWCType(wint_t wc, wctype_t charClass)
+{
+       switch (charClass) {
+               case _ISalnum:
+                       return u_hasBinaryProperty(wc, UCHAR_POSIX_ALNUM);
+               case _ISalpha:
+                       return u_isUAlphabetic(wc);
+               case _ISblank:
+                       return u_isblank(wc);
+               case _IScntrl:
+                       return u_charType(wc) == U_CONTROL_CHAR;
+               case _ISdigit:
+                       return u_isdigit(wc);
+               case _ISgraph:
+                       return u_hasBinaryProperty(wc, UCHAR_POSIX_GRAPH);
+               case _ISlower:
+                       return u_isULowercase(wc);
+               case _ISprint:
+                       return u_hasBinaryProperty(wc, UCHAR_POSIX_PRINT);
+               case _ISpunct:
+                       return u_ispunct(wc);
+               case _ISspace:
+                       return u_isUWhiteSpace(wc);
+               case _ISupper:
+                       return u_isUUppercase(wc);
+               case _ISxdigit:
+                       return u_isxdigit(wc);
+               default:
+                       return 0;
+       }
+}
+
+
+wint_t
+ICUCtypeData::ToWCTrans(wint_t wc, wctrans_t charClass)
+{
+       switch (charClass) {
+               case _ISlower:
+                       return u_tolower(wc);
+               case _ISupper:
+                       return u_toupper(wc);
+               default:
+                       return wc;
+       }
+}
+
+
 }      // namespace BPrivate

Modified: 
haiku/branches/developer/zooey/posix-locale/src/system/libroot/posix/locale/ICULocaleBackend.cpp
===================================================================
--- 
haiku/branches/developer/zooey/posix-locale/src/system/libroot/posix/locale/ICULocaleBackend.cpp
    2010-07-06 20:52:10 UTC (rev 37413)
+++ 
haiku/branches/developer/zooey/posix-locale/src/system/libroot/posix/locale/ICULocaleBackend.cpp
    2010-07-06 21:31:04 UTC (rev 37414)
@@ -113,6 +113,20 @@
 }
 
 
+int
+ICULocaleBackend::IsWCType(wint_t wc, wctype_t charClass)
+{
+       return fCtypeData.IsWCType(wc, charClass);
+}
+
+
+wint_t
+ICULocaleBackend::ToWCTrans(wint_t wc, wctrans_t charClass)
+{
+       return fCtypeData.IsWCType(wc, charClass);
+}
+
+
 const char*
 ICULocaleBackend::_QueryLocale(int category)
 {

Modified: 
haiku/branches/developer/zooey/posix-locale/src/system/libroot/posix/locale/Jamfile
===================================================================
--- 
haiku/branches/developer/zooey/posix-locale/src/system/libroot/posix/locale/Jamfile
 2010-07-06 20:52:10 UTC (rev 37413)
+++ 
haiku/branches/developer/zooey/posix-locale/src/system/libroot/posix/locale/Jamfile
 2010-07-06 21:31:04 UTC (rev 37414)
@@ -14,6 +14,7 @@
        #mbrtowc.c
        #mbsinit.c
        #wcrtomb.c
+       wctype.cpp
 ;
 
 SharedLibrary libroot-addon-locale.so

Added: 
haiku/branches/developer/zooey/posix-locale/src/system/libroot/posix/locale/wctype.cpp
===================================================================
--- 
haiku/branches/developer/zooey/posix-locale/src/system/libroot/posix/locale/wctype.cpp
                              (rev 0)
+++ 
haiku/branches/developer/zooey/posix-locale/src/system/libroot/posix/locale/wctype.cpp
      2010-07-06 21:31:04 UTC (rev 37414)
@@ -0,0 +1,227 @@
+/*
+** Copyright 2010, Oliver Tappe, zooey@xxxxxxxxxxxxxxxx All rights reserved.
+** Distributed under the terms of the Haiku License.
+*/
+
+
+#include <ctype.h>
+#include <string.h>
+#include <wctype.h>
+
+#include "LocaleBackend.h"
+
+
+using BPrivate::gLocaleBackend;
+
+/*
+ * In many of the following functions, we make use of the fact that with
+ * gLocaleBackend == NULL, the POSIX locale is active. Since the POSIX locale
+ * only contains chars 0-127 and those ASCII chars are compatible with the
+ * UTF32 values used in wint_t, we can delegate to the respective ctype
+ * function.
+ */
+
+int
+iswalnum(wint_t wc)
+{
+       if (gLocaleBackend == NULL)
+               return __isctype(wc, _ISalnum);
+
+       return gLocaleBackend->IsWCType(wc, _ISalnum);
+}
+
+
+int
+iswalpha(wint_t wc)
+{
+       if (gLocaleBackend == NULL)
+               return __isctype(wc, _ISalpha);
+
+       return gLocaleBackend->IsWCType(wc, _ISalpha);
+}
+
+
+int
+iswblank(wint_t wc)
+{
+       if (gLocaleBackend == NULL)
+               return __isctype(wc, _ISblank);
+
+       return gLocaleBackend->IsWCType(wc, _ISblank);
+}
+
+
+int
+iswcntrl(wint_t wc)
+{
+       if (gLocaleBackend == NULL)
+               return __isctype(wc, _IScntrl);
+
+       return gLocaleBackend->IsWCType(wc, _IScntrl);
+}
+
+
+int
+iswdigit(wint_t wc)
+{
+       if (gLocaleBackend == NULL)
+               return __isctype(wc, _ISdigit);
+
+       return gLocaleBackend->IsWCType(wc, _ISdigit);
+}
+
+
+int
+iswgraph(wint_t wc)
+{
+       if (gLocaleBackend == NULL)
+               return __isctype(wc, _ISgraph);
+
+       return gLocaleBackend->IsWCType(wc, _ISgraph);
+}
+
+
+int
+iswlower(wint_t wc)
+{
+       if (gLocaleBackend == NULL)
+               return __isctype(wc, _ISlower);
+
+       return gLocaleBackend->IsWCType(wc, _ISlower);
+}
+
+
+int
+iswprint(wint_t wc)
+{
+       if (gLocaleBackend == NULL)
+               return __isctype(wc, _ISprint);
+
+       return gLocaleBackend->IsWCType(wc, _ISprint);
+}
+
+
+int
+iswpunct(wint_t wc)
+{
+       if (gLocaleBackend == NULL)
+               return __isctype(wc, _ISpunct);
+
+       return gLocaleBackend->IsWCType(wc, _ISpunct);
+}
+
+
+int
+iswspace(wint_t wc)
+{
+       if (gLocaleBackend == NULL)
+               return __isctype(wc, _ISspace);
+
+       return gLocaleBackend->IsWCType(wc, _ISspace);
+}
+
+
+int
+iswupper(wint_t wc)
+{
+       if (gLocaleBackend == NULL)
+               return __isctype(wc, _ISupper);
+
+       return gLocaleBackend->IsWCType(wc, _ISupper);
+}
+
+
+int
+iswxdigit(wint_t wc)
+{
+       if (gLocaleBackend == NULL)
+               return __isctype(wc, _ISxdigit);
+
+       return gLocaleBackend->IsWCType(wc, _ISxdigit);
+}
+
+
+int
+iswctype(wint_t wc, wctype_t charClass)
+{
+       if (gLocaleBackend == NULL)
+               return __isctype(wc, charClass);
+
+       return gLocaleBackend->IsWCType(wc, charClass);
+}
+
+
+wint_t
+towlower(wint_t wc)
+{
+       if (gLocaleBackend == NULL)
+               return tolower(wc);
+
+       return gLocaleBackend->ToWCTrans(wc, _ISlower);
+}
+
+
+wint_t
+towupper(wint_t wc)
+{
+       if (gLocaleBackend == NULL)
+               return toupper(wc);
+
+       return gLocaleBackend->ToWCTrans(wc, _ISupper);
+}
+
+
+wint_t
+towctrans(wint_t wc, wctrans_t charClass)
+{
+       if (gLocaleBackend == NULL)
+               return tolower(wc);
+
+       return gLocaleBackend->ToWCTrans(wc, charClass);
+}
+
+
+wctrans_t
+wctrans(const char *charClass)
+{
+       // currently, we do not support any locale-specific character classes
+       if (strcmp(charClass, "tolower") == 0)
+               return _ISlower;
+       if (strcmp(charClass, "toupper") == 0)
+               return _ISupper;
+
+       return 0;
+}
+
+
+wctype_t
+wctype(const char *property)
+{
+       // currently, we do not support any locale-specific properties
+       if (strcmp(property, "alnum") == 0)
+               return _ISalnum;
+       if (strcmp(property, "alpha") == 0)
+               return _ISalpha;
+       if (strcmp(property, "blank") == 0)
+               return _ISblank;
+       if (strcmp(property, "cntrl") == 0)
+               return _IScntrl;
+       if (strcmp(property, "digit") == 0)
+               return _ISdigit;
+       if (strcmp(property, "graph") == 0)
+               return _ISgraph;
+       if (strcmp(property, "lower") == 0)
+               return _ISlower;
+       if (strcmp(property, "print") == 0)
+               return _ISprint;
+       if (strcmp(property, "punct") == 0)
+               return _ISpunct;
+       if (strcmp(property, "space") == 0)
+               return _ISspace;
+       if (strcmp(property, "upper") == 0)
+               return _ISupper;
+       if (strcmp(property, "xdigit") == 0)
+               return _ISxdigit;
+
+       return 0;
+}


Other related posts:

  • » [haiku-commits] r37414 - in haiku/branches/developer/zooey/posix-locale: headers/posix headers/private/libroot/locale src/system/libroot src/system/libroot/posix/glibc src/system/libroot/posix/locale - zooey