File:  [RetroPC.NET] / np2 / codecnv / ucs2utf8.c
Revision 1.1: download - view: text, annotated - select for diffs
Sat Feb 12 21:13:56 2005 JST (20 years, 8 months ago) by yui
Branches: MAIN
CVS tags: HEAD
move codecnv (T.Yui)

#include	"compiler.h"
#include	"codecnv.h"


UINT codecnv_ucs2toutf8(char *dst, UINT dcnt, const UINT16 *src, UINT scnt) {

	UINT	orgdcnt;
	UINT	c;

	(void)scnt;
	orgdcnt = dcnt;
	if (dcnt == 0) {
		dst = NULL;
	}

	dcnt--;
	while(dcnt) {
		c = *src++;
		if (!c) {
			break;
		}
		else if (c < 0x80) {
			dcnt--;
			if (dst) {
				dst[0] = (char)c;
				dst += 1;
			}
		}
		else if (c < 0x800) {
			if (dcnt < 2) {
				break;
			}
			dcnt -= 2;
			if (dst) {
				dst[0] = (char)(0xc0 + ((c >> 6) & 0x1f));
				dst[1] = (char)(0x80 + ((c >> 0) & 0x3f));
				dst += 2;
			}
		}
		else {
			if (dcnt < 3) {
				break;
			}
			dcnt -= 3;
			if (dst) {
				dst[0] = (char)(0xe0 + ((c >> 12) & 0x0f));
				dst[1] = (char)(0x80 + ((c >> 6) & 0x3f));
				dst[2] = (char)(0x80 + ((c >> 0) & 0x3f));
				dst += 3;
			}
		}
	}
	if (dst) {
		dst[0] = '\0';
	}
	return((UINT)(orgdcnt - dcnt));
}


RetroPC.NET-CVS <cvs@retropc.net>