aboutsummaryrefslogtreecommitdiff
path: root/utf16.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2012-03-25 20:00:08 +0000
committerMike Buland <eichlan@xagasoft.com>2012-03-25 20:00:08 +0000
commit469bbcf0701e1eb8a6670c23145b0da87357e178 (patch)
treeb5b062a16e46a6c5d3410b4e574cd0cc09057211 /utf16.cpp
parentee1b79396076edc4e30aefb285fada03bb45e80d (diff)
downloadlibbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.tar.gz
libbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.tar.bz2
libbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.tar.xz
libbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.zip
Code is all reorganized. We're about ready to release. I should write up a
little explenation of the arrangement.
Diffstat (limited to 'utf16.cpp')
-rw-r--r--utf16.cpp42
1 files changed, 0 insertions, 42 deletions
diff --git a/utf16.cpp b/utf16.cpp
deleted file mode 100644
index eedb521..0000000
--- a/utf16.cpp
+++ /dev/null
@@ -1,42 +0,0 @@
1#include <stdio.h>
2#include <stdint.h>
3
4void bitprint( uint16_t u )
5{
6 for( int i = 15; i >= 0; i-- )
7 printf("%c", (u&(1<<i))?'1':'0');
8 printf("\n");
9}
10
11void bitprint( uint32_t u )
12{
13 for( int i = 31; i >= 0; i-- )
14 printf("%c", (u&(1<<i))?'1':'0');
15 printf("\n");
16}
17
18void utoutf16( uint32_t in, uint16_t &outHi, uint16_t &outLo )
19{
20 outHi = (((in-0x10000)>>10)&0x3FF)| 0xD800u;
21 outLo = ((in-0x10000)&0x3FF)| 0xDC00u;
22 printf("0x%X == 0x%X, 0x%X\n", in, outHi, outLo );
23}
24
25int32_t utf16tou( uint16_t hi, uint16_t lo )
26{
27 return (((uint32_t)hi&0x3FF)<<10 | lo&0x3FF)+0x10000;
28}
29
30int main()
31{
32 bitprint( 0xD800u );
33 bitprint( 0xDC00u );
34 uint16_t hi, lo;
35 utoutf16( 0x1D11E, hi, lo ); // Cat face with wry smile
36 utoutf16( 0x10FFFD, hi, lo ); // Cat face with wry smile
37 utoutf16( 0x1F63C, hi, lo ); // Cat face with wry smile
38 bitprint( hi );
39 bitprint( lo );
40 printf("0x%X\n", utf16tou( hi, lo ) );
41 return 0;
42}