On Tue, Sep 27, 2011 at 8:35 PM, Ozkan Sezer <seze...@gmail.com> wrote:
> On Tue, Sep 27, 2011 at 8:28 PM, Kai Tietz <ktiet...@googlemail.com> wrote:
>> 2011/9/27 Ozkan Sezer <seze...@gmail.com>:
>>> On Tue, Sep 27, 2011 at 3:48 PM, Ozkan Sezer <seze...@gmail.com> wrote:
>>>> On Tue, Sep 27, 2011 at 2:01 PM, Ruben Van Boxem
>>>> <vanboxem.ru...@gmail.com> wrote:
>>>>> 2011/9/26 Kai Tietz <ktiet...@googlemail.com>
>>>>>>
>>>>>> 2011/9/26 Ruben Van Boxem <vanboxem.ru...@gmail.com>:
>>>>>> > Why does mingw-w64 not have a uchar.h header file? There's only a few
>>>>>> > typedefs and some functions (which can easily be implemented through
>>>>>> > the
>>>>>> > Win32 API IMHO).
>>>>>> >
>>>>>> > See the draft proposal here:
>>>>>> > http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1040.pdf
>>>>>> >
>>>>>> > The reason I ask is because the C++11 standard mentions this header and
>>>>>> > its
>>>>>> > C++ counterpart <cuchar>. Although the functions aren't available in
>>>>>> > msvcrt,
>>>>>> > I'm sure I can come up with an implementation if necessary (based on
>>>>>> > WideCharToMultiByte and some other code to get as far as utf32... hmm
>>>>>> > I'll
>>>>>> > have to think about that). For the UTF-32 bits there's code floating
>>>>>> > around
>>>>>> > all over the internet, like here:
>>>>>> > http://bytes.com/topic/c/answers/517850-converting-utf-16-utf-32-a
>>>>>> > which
>>>>>> > would definitely work with a bit of testing and refactoring.
>>>>>> >
>>>>>> > Please tell me what you think about this idea.
>>>>>> >
>>>>>> > Ruben
>>>>>>
>>>>>> Sounds interesting. WideCharToMultiByte/MultiByteToWideChar API could
>>>>>> handle this.
>>>>>> As we don't have here API-conflicts to msvcrt's API, I would give it a
>>>>>> try.
>>>>>>
>>>>>> Patches are welcome for this.
>>>>>
>>>>> Attached is a simple implementation that falls back to C's wcrtomb and
>>>>> mbrtowc for char16_t (should indirectly be a wchar_t), as these handle the
>>>>> necessary error conditions already.
>>>>>
>>>>> The char32_t bits are manual bit checking. Each case is handled
>>>>> individually, and the result is built up if all conditions are met.
>>>>>
>>>>> I copied and adapted a disclaimer and some more information from stdint.h.
>>>>> The typedefs are not allowed for C++11, as these must be distinct types
>>>>> (implemented in the compiler). Clang had this fixed in r117038, GCC in
>>>>> 4.4.
>>>>> This made me think that ifdef __cplusplus was enough (GCC 4.4 is the first
>>>>> real mingw-w64 capable GCC, and Clang is still quite far from usable
>>>>> IMHO).
>>>>>
>>>>> Ruben
>>>>
>>>> Something is clearly wrong with the gcc version checking: if you
>>>> want to typedef when gcc < 4.4, that line in uchar.h should read
>>>> || (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 4))
>>>> ... I guess.
>>>>
>>>> There are also some other errors, I fixed partially. See attached.
>>>> gcc44 compiles it. g++44 does _NOT_ compile it _unless_ I use
>>>> -std=c++0x or gnu++0x
>>>>
>>>> Didn't inspect functions' code correctness
>>>>
>>>> --
>>>> O.S.
>>>>
>>>
>>> Attached new ones with slightly better gcc check
>>>
>>> --
>>> O.S.
>>
>> Patch looks fine to me.
>
> One thing: As I mentioned above, the if !defined(__cplusplus)
> check is not good enough, because with g++ the types are only
> defined in c++0x mode. Don't know anything better to do there.
>
>> I would like to see here some testcases for
>> the functions. At least for the USV 32 variant.
>>
>
> Ruben?
Attached one very basic but necessary test
>
>> Cheers,
>> Kai
>
> --
> O.S.
>
#define COMPILETIME_CHECK
#include <uchar.h>
#if !defined(COMPILETIME_CHECK)
#include <stdlib.h>
#endif
int main (void)
{
/* wchar_t should compatible to char16_t on Windows */
#if defined(COMPILETIME_CHECK)
typedef int dummy[2 * (sizeof(wchar_t) == sizeof(char16_t)) - 1];
#else /*if defined(RUNTIME_CHECK)*/
if (sizeof(wchar_t) != sizeof(char16_t))
abort ();
#endif
return 0;
}
------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1
_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public