aboutsummaryrefslogtreecommitdiff
path: root/src/utfstring.cpp
blob: 0e2060b36d6586da230954acd41d3841be0295ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
 * Copyright (C) 2007-2011 Xagasoft, All rights reserved.
 *
 * This file is part of the libbu++ library and is released under the
 * terms of the license contained in the file LICENSE.
 */

#include "bu/utfstring.h"

#include "bu/string.h"

Bu::UtfString::UtfString()
{
}

Bu::UtfString::~UtfString()
{
}

#include "bu/sio.h"
using Bu::sio;

void Bu::UtfString::debugUtf8( const Bu::String &sUtf8 )
{
	static uint8_t lmask[8] = {
		0x00,
		0x01,
		0x03,
		0x07,
		0x0f,
		0x1f,
		0x3f,
		0x7f
	};
	for( Bu::String::const_iterator i = sUtf8.begin(); i; i++ )
	{
		if( i != sUtf8.begin() )
			sio << ", ";
		if( ((int)(uint8_t)*i)&0x80 )
		{
//			sio << "Flag byte: " << Bu::Fmt().radix(2).width(8).fill('0')
//				<< (int)(uint8_t)*i << sio.nl;
			int iBytes = 1;
			for(; (((uint8_t)(*i))<<iBytes)&0x80; iBytes++ ) { }
//			sio << "iBytes = " << iBytes << sio.nl;
			point uPt = ((*i) & lmask[7-iBytes])<<(6*(iBytes-1));
//			sio << "mask: " << Bu::Fmt().radix(2).width(8).fill('0')
//				<< (int)lmask[7-iBytes] << sio.nl;
			for( iBytes--; iBytes >= 1; iBytes-- )
			{
//				sio << "iBytes = " << iBytes << ", shift = " << (6*(iBytes-1))
//					<< sio.nl;
//				sio << "next: " << Bu::Fmt().radix(2).width(8).fill('0')
//					<< (int)(uint8_t)*i << sio.nl
//					<< "mask: " << Bu::Fmt().radix(2).width(8).fill('0')
//					<< (int)lmask[6] << sio.nl;
				i++;
				uPt |= ((*i)&lmask[6])<<(6*(iBytes-1));
			}
			sio << uPt;
//			sio << " (" << Bu::Fmt( 8, 2 ).fill('0')
//				<< uPt << ")";
		}
		else
		{
			sio << (int)((uint8_t)*i);
		}
	}
	sio << sio.nl;
}