示例#1
0
文件: jl_uv.c 项目: pridkett/julia
DLLEXPORT int jl_pututf8(uv_stream_t *s, uint32_t wchar )
{
    char buf[8];
    if (wchar < 0x80)
        return jl_putc((int)wchar, s);
    size_t n = u8_toutf8(buf, 8, &wchar, 1);
    return jl_write(s, buf, n);
}
示例#2
0
文件: jl_uv.c 项目: jskDr/julia
DLLEXPORT int jl_pututf8_copy(uv_stream_t *s, uint32_t wchar, void *uvw, void *writecb)
{
    char buf[8];
    if (wchar < 0x80)
        return jl_putc_copy((int)wchar, s, uvw, writecb);
    size_t n = u8_toutf8(buf, 8, &wchar, 1);
    return jl_write_copy(s, buf, n, (uv_write_t*)uvw, writecb);
}
示例#3
0
std::shared_ptr<const Base_type> Type::generate_new_placeholder_type() {
	u_int32_t character = 0x03B1 + placeholder_counter;
	char buff[5];
	u8_toutf8(buff, 5, &character, 1);
	auto type = std::make_shared<Placeholder_type>(std::string { buff });
	placeholder_counter++;
	Type::placeholder_types.push_back(type);
	return type;
}
示例#4
0
int encode_to_utf8(char *dest, int sz, const char *src, int srcsz)
{
	wchar_t *unicode;
	int wchars, err;

	wchars = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, src, srcsz, NULL, 0);
	if(wchars == 0) {
		fprintf(stderr, "Unicode translation error %d\n", GetLastError());
		return -1;
	}

	unicode = (wchar_t *) alloca((wchars + 1) * sizeof(unsigned short));
	err = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, src, srcsz, unicode, wchars);
	if(err != wchars) {
		fprintf(stderr, "Unicode translation error %d\n", GetLastError());
		return -1;
	}
	unicode[wchars] = L'\0';
	return u8_toutf8(dest, sz, unicode, wchars);
}
示例#5
0
int unichars(const char* src)
{
   long ssz = strlen(src);
   u_int32_t* unic = NULL;
   u_int32_t* myunic = NULL;
   char* mys = NULL;

   int i = 0;
   int j = 0;
   int n = 0, nn = 0;
   int m = 0;
   bool repeated = false;

   unic = (u_int32_t*) malloc(ssz*sizeof(u_int32_t));
   myunic = (u_int32_t*) malloc(ssz*sizeof(u_int32_t));
   mys = (char*) malloc(ssz*sizeof(char));

   if(unic==NULL)
	exit(1);
   else if(myunic==NULL)
   {
	free(unic);
	exit(2);
   }
   else if(mys==NULL)
   {
	free(unic);
	free(myunic);
	exit(3);
   }

   m = u8_toucs(unic, ssz, (char*)src, -1);

   for(i=0; i<m; i++)
   {
	repeated = false;
	for(j=0; j<i; j++)
	{
	   if(unic[i] == unic[j])
	   {
		repeated = true;
		break;
	   }
	}
	if(unic[i]>127 && !repeated)
	   myunic[n++] = unic[i];
   }
   myunic[n] = 0;

   nn = u8_toutf8(mys, ssz, myunic, -1);

   printf("\n*************************\n");
   printf("%s", mys);
   printf("\n*************************\n");

   free(mys);
   free(unic);
   free(myunic);

   return nn;
}