poke-devel
[Top][All Lists]
Advanced

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

Re: Questions about how to implement pickles/utf8.pk


From: Mohammad-Reza Nabipoor
Subject: Re: Questions about how to implement pickles/utf8.pk
Date: Thu, 17 Sep 2020 10:04:15 +0430

Hi, Jose.

Thanks for your answers :+1:


On Thu, Sep 17, 2020 at 12:58:05AM +0200, Jose E. Marchesi wrote:


I would use something in this spirit:

deftype UTF8_CodePoint = uint<21>;

deftype UTF8 =
 struct
 {
   byte head;

   defvar bytes
     = (head > 0x11110000 ? 4
        : head > 0x11100000 ? 3
        : head > 0x11000000 ? 2
        : 1);

   byte[bytes - 1] tail;

   method get_value = UTF8_CodePoint:
     {
       defvar size = tail'size + 1;

       [... decode value from head and bytes and return it ...]
     }

   method set_value = (UTF8_CodePoint value) void:
     {
       [... set head and tail ...]
     }

   method _print = void:
     {
       printf ("#<%v>", get_value)
     }
 };


:+1:


## Question 4

I cannot write `utf8_encode` function for `UTF8_1`, because union construction
does not work (like the problem for pinned structs [Bug 26527][2]).

I am not aware of any problem with union constructors.  How they don't
work?

I mean field initialization doesn't work (like in pinned structs).

```
(poke) UTF8_1 {d2=[0xd8UB, 0xb3UB]}
UTF8_1 {d1=[0x0UB]}
```


Regards,
Mohammad-Reza


reply via email to

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