Problem with wstring output

Pages: 12
I was talking to Duoas.
I actually dislike all of them. None of them handle errors very well. The stuff I am actually working on does much better. I haven't tested it for speed yet...

If I can just figure out what's wrong with the vtable for the codecvt facet.
http://www.cplusplus.com/forum/general/18596/
They way I do error checking is in a different function, before calling the conversion function. I like to keep checking and conversion separate.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
bool isValidUTF8(const char *buffer,ulong size){
	const uchar *unsigned_buffer=(const uchar *)buffer;
	for (ulong a=0;a<size;a++){
		ulong char_len;
		if (!(*unsigned_buffer&128))
			char_len=1;
		else if ((*unsigned_buffer&224)==192)
			char_len=2;
		else if ((*unsigned_buffer&240)==224)
			char_len=3;
		else if ((*unsigned_buffer&248)==240)
			char_len=4;
		else
			return 0;
		unsigned_buffer++;
		if (char_len<2)
			continue;
		a++;
		for (ulong b=1;b<char_len;b++,a++,unsigned_buffer++)
			if (*unsigned_buffer<0x80 || (*unsigned_buffer&0xC0)!=0x80)
				return 0;
	}
	return 1;
}

It doesn't check for overlong sequences or other types of errors. If the stream can possibly be parsed, it's considered valid.
Topic archived. No new replies allowed.
Pages: 12