public static char[] utf8_string_to_ucs2_string( byte[] bytes )
{
int nb= bytes.Length;
int nc= utf8length( bytes, nb );
char[] chars= new char[nc];
int i= 0;
for ( int j= 0 ; j < nc ; ++j )
{
byte b= bytes[i];
if ((b & 0x80) == 0)
{
chars[j]= (char)b;
++i;
}
else if ((b & 0x20) == 0)
{
chars[j]= (char)(((b & 0x1F) << 6) | (bytes[i+1] & 0x3F));
i+= 2;
}
else
{
chars[j]= (char)( ((b & 0x0F) << 12)
| ((bytes[i+1] & 0x3F) << 6)
| (bytes[i+2] & 0x3F));
i+= 3;
}
}
return chars;
}