Exemplo n.º 1
0
char *utf8ndup(const char *s, size_t n) {
	/* XXX any suggestions for function name? IDKHTNI_ndup()? (IDKHTNI - I Don't Know How To Name It) */
	char *tmp = xstrndup(s, n);

	if (!tmp) return NULL;

	if (!is_utf8_string(s)) return tmp;

	if (n<0) n = xstrlen(tmp);

	while (!is_utf8_string(tmp) && n--)
		*(tmp + n) = 0;

	return tmp;
}
Exemplo n.º 2
0
CALLER_OWN SV *owl_new_sv(const char * str)
{
  SV *ret = newSVpv(str, 0);
  if (is_utf8_string((const U8 *)str, strlen(str))) {
    SvUTF8_on(ret);
  } else {
    char *escape = owl_escape_highbit(str);
    owl_function_error("Internal error! Non-UTF-8 string encountered:\n%s", escape);
    g_free(escape);
  }
  return ret;
}
Exemplo n.º 3
0
LPSTR __cdecl pgp_decode(HANDLE context, LPCSTR szEncMsg)
{
	pCNTX ptr = get_context_on_id(context);
	if (!ptr)
		return NULL;
	mir_free(ptr->tmp);

	LPSTR szNewMsg = NULL;
	LPSTR szOldMsg = pgp_decrypt(ptr, szEncMsg);

	if (szOldMsg) {
		if (!is_7bit_string(szOldMsg) && !is_utf8_string(szOldMsg)) {
			szNewMsg = mir_utf8encode(szOldMsg);
		}
		else
			szNewMsg = mir_strdup(szOldMsg);
	}
	return ptr->tmp = szNewMsg;
}
Exemplo n.º 4
0
EXTERN bool
probably_utf8_chunk(pTHX_ char *s, STRLEN len)
{
    char *e = s + len;
    STRLEN clen;

    /* ignore partial utf8 char at end of buffer */
    while (s < e && UTF8_IS_CONTINUATION((U8)*(e - 1)))
	e--;
    if (s < e && UTF8_IS_START((U8)*(e - 1)))
	e--;
    clen = len - (e - s);
    if (clen && UTF8SKIP(e) == clen) {
	/* all promised continuation bytes are present */
	e = s + len;
    }

    if (!has_hibit(s, e))
	return 0;

    return is_utf8_string((U8*)s, e - s);
}
Exemplo n.º 5
0
LPSTR __cdecl pgp_decode(HANDLE context, LPCSTR szEncMsg)
{
	pCNTX ptr = get_context_on_id(context);
	if(!ptr) return NULL;

	LPSTR szNewMsg = NULL;
	LPSTR szOldMsg = pgp_decrypt(ptr, szEncMsg);

	if(szOldMsg) {
		if( !is_7bit_string(szOldMsg) && !is_utf8_string(szOldMsg) ) {
			int slen = strlen(szOldMsg)+1;
			LPWSTR wszMsg = (LPWSTR) alloca(slen*sizeof(WCHAR));
			MultiByteToWideChar(CP_ACP, 0, szOldMsg, -1, wszMsg, slen*sizeof(WCHAR));
			szNewMsg = _strdup(utf8encode(wszMsg));
		}
		else {
			szNewMsg = _strdup(szOldMsg);
		}
	}
	SAFE_FREE(ptr->tmp);
	ptr->tmp = szNewMsg;
	return szNewMsg;
}
Exemplo n.º 6
0
IV
PerlIOEncode_fill(pTHX_ PerlIO * f)
{
    PerlIOEncode *e = PerlIOSelf(f, PerlIOEncode);
    dSP;
    IV code = 0;
    PerlIO *n;
    SSize_t avail;

    if (PerlIO_flush(f) != 0)
	return -1;
    n  = PerlIONext(f);
    if (!PerlIO_fast_gets(n)) {
	/* Things get too messy if we don't have a buffer layer
	   push a :perlio to do the job */
	char mode[8];
	n  = PerlIO_push(aTHX_ n, &PerlIO_perlio, PerlIO_modestr(f,mode), Nullsv);
	if (!n) {
	    Perl_die(aTHX_ "panic: cannot push :perlio for %p",f);
	}
    }
    PUSHSTACKi(PERLSI_MAGIC);
    SPAGAIN;
    ENTER;
    SAVETMPS;
  retry:
    avail = PerlIO_get_cnt(n);
    if (avail <= 0) {
	avail = PerlIO_fill(n);
	if (avail == 0) {
	    avail = PerlIO_get_cnt(n);
	}
	else {
	    if (!PerlIO_error(n) && PerlIO_eof(n))
		avail = 0;
	}
    }
    if (avail > 0 || (e->flags & NEEDS_LINES)) {
	STDCHAR *ptr = PerlIO_get_ptr(n);
	SSize_t use  = (avail >= 0) ? avail : 0;
	SV *uni;
	char *s = NULL;
	STRLEN len = 0;
	e->base.ptr = e->base.end = (STDCHAR *) NULL;
	(void) PerlIOEncode_get_base(aTHX_ f);
	if (!e->dataSV)
	    e->dataSV = newSV(0);
	if (SvTYPE(e->dataSV) < SVt_PV) {
	    sv_upgrade(e->dataSV,SVt_PV);
	}
	if (e->flags & NEEDS_LINES) {
	    /* Encoding needs whole lines (e.g. iso-2022-*)
	       search back from end of available data for
	       and line marker
	     */
	    STDCHAR *nl = ptr+use-1;
	    while (nl >= ptr) {
		if (*nl == '\n') {
		    break;
		}
		nl--;
	    }
	    if (nl >= ptr && *nl == '\n') {
		/* found a line - take up to and including that */
		use = (nl+1)-ptr;
	    }
	    else if (avail > 0) {
		/* No line, but not EOF - append avail to the pending data */
		sv_catpvn(e->dataSV, (char*)ptr, use);
		PerlIO_set_ptrcnt(n, ptr+use, 0);
		goto retry;
	    }
	    else if (!SvCUR(e->dataSV)) {
		goto end_of_file;
	    }
	}
	if (SvCUR(e->dataSV)) {
	    /* something left over from last time - create a normal
	       SV with new data appended
	     */
	    if (use + SvCUR(e->dataSV) > e->base.bufsiz) {
		if (e->flags & NEEDS_LINES) {
		    /* Have to grow buffer */
		    e->base.bufsiz = use + SvCUR(e->dataSV);
		    PerlIOEncode_get_base(aTHX_ f);
		}
		else {
	       use = e->base.bufsiz - SvCUR(e->dataSV);
	    }
	    }
	    sv_catpvn(e->dataSV,(char*)ptr,use);
	}
	else {
	    /* Create a "dummy" SV to represent the available data from layer below */
	    if (SvLEN(e->dataSV) && SvPVX_const(e->dataSV)) {
		Safefree(SvPVX_mutable(e->dataSV));
	    }
	    if (use > (SSize_t)e->base.bufsiz) {
		if (e->flags & NEEDS_LINES) {
		    /* Have to grow buffer */
		    e->base.bufsiz = use;
		    PerlIOEncode_get_base(aTHX_ f);
		}
		else {
	       use = e->base.bufsiz;
	    }
	    }
	    SvPV_set(e->dataSV, (char *) ptr);
	    SvLEN_set(e->dataSV, 0);  /* Hands off sv.c - it isn't yours */
	    SvCUR_set(e->dataSV,use);
	    SvPOK_only(e->dataSV);
	}
	SvUTF8_off(e->dataSV);
	PUSHMARK(sp);
	XPUSHs(e->enc);
	XPUSHs(e->dataSV);
	XPUSHs(e->chk);
	PUTBACK;
	if (call_method("decode", G_SCALAR) != 1) {
	    Perl_die(aTHX_ "panic: decode did not return a value");
	}
	SPAGAIN;
	uni = POPs;
	PUTBACK;
	/* Now get translated string (forced to UTF-8) and use as buffer */
	if (SvPOK(uni)) {
	    s = SvPVutf8(uni, len);
#ifdef PARANOID_ENCODE_CHECKS
	    if (len && !is_utf8_string((U8*)s,len)) {
		Perl_warn(aTHX_ "panic: decode did not return UTF-8 '%.*s'",(int) len,s);
	    }
#endif
	}
	if (len > 0) {
	    /* Got _something */
	    /* if decode gave us back dataSV then data may vanish when
	       we do ptrcnt adjust - so take our copy now.
	       (The copy is a pain - need a put-it-here option for decode.)
	     */
	    sv_setpvn(e->bufsv,s,len);
	    e->base.ptr = e->base.buf = (STDCHAR*)SvPVX(e->bufsv);
	    e->base.end = e->base.ptr + SvCUR(e->bufsv);
	    PerlIOBase(f)->flags |= PERLIO_F_RDBUF;
	    SvUTF8_on(e->bufsv);

	    /* Adjust ptr/cnt not taking anything which
	       did not translate - not clear this is a win */
	    /* compute amount we took */
	    use -= SvCUR(e->dataSV);
	    PerlIO_set_ptrcnt(n, ptr+use, (avail-use));
	    /* and as we did not take it it isn't pending */
	    SvCUR_set(e->dataSV,0);
	} else {
	    /* Got nothing - assume partial character so we need some more */
	    /* Make sure e->dataSV is a normal SV before re-filling as
	       buffer alias will change under us
	     */
	    s = SvPV(e->dataSV,len);
	    sv_setpvn(e->dataSV,s,len);
	    PerlIO_set_ptrcnt(n, ptr+use, (avail-use));
	    goto retry;
	}
    }
    else {
    end_of_file:
	code = -1;
	if (avail == 0)
	    PerlIOBase(f)->flags |= PERLIO_F_EOF;
	else
	    PerlIOBase(f)->flags |= PERLIO_F_ERROR;
    }
    FREETMPS;
    LEAVE;
    POPSTACK;
    return code;
}
Exemplo n.º 7
0
extern "C" int output_baijiaxing() {
	std::vector<std::string> names;
	names.push_back("��Ǯ���� ����֣��");
	names.push_back("������� ������");
	names.push_back("�������� ����ʩ��"); 
	names.push_back("�ײ��ϻ� ��κ�ս�");
	names.push_back("��л���� ��ˮ���"); 
	names.push_back("�����˸� �ɷ�����"); 
	names.push_back("³Τ���� ��ﻨ��"); 
	names.push_back("����Ԭ�� �ᱫʷ��"); 
	names.push_back("�����Ѧ �׺�����"); 
	names.push_back("�����ޱ� ��������"); 
	names.push_back("����ʱ�� Ƥ���뿵"); 
	names.push_back("����Ԫ�� ����ƽ��"); 
	names.push_back("�������� Ҧ��տ��"); 
	names.push_back("��ë��� �ױ����"); 
	names.push_back("�Ʒ��ɴ� ̸��é��"); 
	names.push_back("�ܼ����� ��ף����"); 
	names.push_back("�������� ϯ����ǿ"); 
	names.push_back("��·¦Σ ��ͯ�չ�"); 
	names.push_back("÷ʢ�ֵ� ��������"); 
	names.push_back("���IJ��� �������"); 
	names.push_back("����֧�� �ù�¬Ī"); 
	names.push_back("�������� �ɽ�Ӧ��"); 
	names.push_back("�����ڵ� ��������"); 
	names.push_back("������ʯ �޼�ť��"); 
	names.push_back("�����ϻ� ��½����"); 
	names.push_back("����춻� ����ҷ�"); 
	names.push_back("���ഢ�� ��������"); 
	names.push_back("���θ��� �ڽ��͹�"); 
	names.push_back("����ɽ�� �������"); 
	names.push_back("ȫۭ���� ��������"); 
	names.push_back("�����ﱩ ��������"); 
	names.push_back("������� ��ղ����"); 
	names.push_back("Ҷ��˾�� ۬�輻��"); 
	names.push_back("ӡ�ް׻� ��ۢ�Ӷ�"); 
	names.push_back("���̼��� ׿������"); 
	names.push_back("�������� ���ܲ�˫"); 
	names.push_back("��ݷ���� ̷���ͷ�"); 
	names.push_back("������� Ƚ��۪Ӻ"); 
	names.push_back("�S�ɣ�� �ţ��ͨ"); 
	names.push_back("�����༽ ۣ����ũ"); 
	names.push_back("�±�ׯ�� �����ֳ�"); 
	names.push_back("Ľ����ϰ �°�����"); 
	names.push_back("������� ��������"); 
	names.push_back("�߾Ӻⲽ ��������"); 
	names.push_back("����Ŀ� ��»�ڶ�"); 
	names.push_back("ŷ����� εԽ��¡"); 
	names.push_back("ʦ������ �˹�����"); 
	names.push_back("�������� �Ǽ��Ŀ�"); 
	names.push_back("����ɳؿ �������"); 
	names.push_back("�������� ��󾣺�"); 
	names.push_back("����Ȩ�� ���滸��"); 
	names.push_back("��ٹ˾�� �Ϲ�ŷ��"); 
	names.push_back("�ĺ���� ���˶���"); 
	names.push_back("�����ʸ� ξ�ٹ���"); 
	names.push_back("�̨��ұ �������");
	names.push_back("���ڵ��� ̫������"); 
	names.push_back("�������� ��ԯ���"); 
	names.push_back("�������� ����Ľ��"); 
	names.push_back("˾ͽ˾�� �ټ�����");

	// names.push_back("ξ����� ̫��");

	for (int i=0; i<names.size(); i++) {
		std::string utf8_name = ansi2utf8(names.at(i));
		char inbuf[1024] = {0};
		strcpy(inbuf, utf8_name.c_str());

		char outbuf[4096] = {0};
		char overage_buff[7] = {0};

		int add_blank = 1;
		int polyphone_support = 1;
		int first_letter_only = 0;
		int convert_double_char = 0;

		if (!is_utf8_string(inbuf)) {
			printf("File encoding is not utf-8!\n");
			return -1;
		}

		// printf("No:%d ", i);
		// printf("No:%d name:%s", names.at(i).c_str());
		utf8_to_pinyin(inbuf,
			outbuf,
			first_letter_only,
			polyphone_support,
			add_blank,
			convert_double_char,
			overage_buff);
		printf("\n");

		printf("No:%d name:%s, pinyin:%s",i, names.at(i).c_str(), outbuf);
	}
}