flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > utf8.inc

Author
Thread Post new topic Reply to topic
skykrnl



Joined: 17 Nov 2008
Posts: 21
skykrnl 03 Aug 2009, 17:30
Code:

; utf-8 -> utf-16

macro du [arg]
{
  local   current,char

    if ~ arg eqtype ''
                dw arg
      else
                virtual at 0
                        db arg
                      count = $
           end virtual

             current = 0
         while current < count
                    virtual at 0
                                db arg
                              load char byte from current
                         current = current + 1
                               if      char <= 0C0h
                                     wide = char
                         else if char < 0E0h
                                      wide = char and 11111b
                                      repeat 1
                                            load char byte from current
                                         wide = wide shl 6 + (char and 111111b)
                                              current = current + 1
                                       end repeat
                          else if char < 0F0h
                                      wide = char and 1111b
                                       repeat 2
                                            load char byte from current
                                         wide = wide shl 6 + (char and 111111b)
                                              current = current + 1
                                       end repeat
                          else if char < 0F8h
                                      wide = char and 111b
                                        repeat 3
                                            load char byte from current
                                         wide = wide shl 6 + (char and 111111b)
                                              current = current + 1
                                       end repeat
                          else if char < 0FCh
                                      wide = char and 11b
                                 repeat 4
                                            load char byte from current
                                         wide = wide shl 6 + (char and 111111b)
                                              current = current + 1
                                       end repeat
                          else
                                        wide = char and 1b
                                  repeat 5
                                            load char byte from current
                                         wide = wide shl 6 + (char and 111111b)
                                              current = current + 1
                                       end repeat
                          end if
                      end virtual

                     if wide < 10000h
                         dw wide
                     else
                                dw 0D7C0h + wide shr 10, 0DC00h or (wide and 3FFh)
                  end if

          end while       ;endwhile current < count
        end if
}

struc du [args]
{
   common label . word
 du args
}
    
Post 03 Aug 2009, 17:30
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8361
Location: Kraków, Poland
Tomasz Grysztar 12 Aug 2009, 11:08
Is it better than the one provided in the official package? Could you make some comment?
Post 12 Aug 2009, 11:08
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.