Ejemplo n.º 1
0
/* NOTE: despite what you would expect, 'file_name' is actually a path.
 * With windoze style backlashes, ofc.
 */
static struct efi_file_handle *file_open(struct file_system *fs,
		struct file_handle *parent, s16 *file_name, u64 mode)
{
	struct file_handle *fh;
	char f0[MAX_UTF8_PER_UTF16] = {0};
	int plen = 0;
	int flen = 0;

	if (file_name) {
		utf16_to_utf8((u8 *)f0, (u16 *)file_name, 1);
		flen = utf16_strlen((u16 *)file_name);
	}

	/* we could have a parent, but also an absolute path: */
	if (f0[0] == '\\') {
		plen = 0;
	} else if (parent) {
		plen = strlen(parent->path) + 1;
	}

	/* +2 is for null and '/' */
	fh = calloc(1, sizeof(*fh) + plen + (flen * MAX_UTF8_PER_UTF16) + 2);

	fh->base = efi_file_handle_protocol;
	fh->fs = fs;

	if (parent) {
		char *p = fh->path;

		if (plen > 0) {
			strcpy(p, parent->path);
			p += plen - 1;
			*p++ = '/';
		}

		utf16_to_utf8((u8 *)p, (u16 *)file_name, flen);

		if (sanitize_path(fh->path))
			goto error;

		/* check if file exists: */
		if (set_blk_dev(fh))
			goto error;

		if (!((mode & EFI_FILE_MODE_CREATE) || fs_exists(fh->path)))
			goto error;

		/* figure out if file is a directory: */
		fh->isdir = is_dir(fh);
	} else {
		fh->isdir = 1;
		strcpy(fh->path, "");
	}

	return &fh->base;

error:
	free(fh);
	return NULL;
}
Ejemplo n.º 2
0
void CWndStyleEditor::OnBnClickedSelectPic()
{
	if(NULL == SQRGUIStyleManager::GetInst()->GetActiveStyle())
		return;
	// TODO: Add your control notification handler code here
	CString FileName = GetFileName(true, L"GUI Texture (*.tex *.dds)|*.tex;*.dds||");
	
	SQRGUIStyle* pStyle = SQRGUIStyleManager::GetInst()->GetActiveStyle();
	
	CString CurPath = utf8_to_utf16(pStyle->GetTexturePath()).c_str();
	CurPath.MakeLower();
	wstring Str = FileName.GetBuffer();
	wstring TexStr = Str.substr(Str.rfind(L"\\") + 1, Str.size());
	CString TexPath = Str.substr(0, Str.rfind(L"\\") + 1).c_str();

	if(m_pStyleStruct!=NULL &&
		Str.size()>0 &&
		m_pStyleStruct->m_TexString!=utf16_to_utf8(TexStr).c_str() &&
		TexPath == CurPath )
	{
		m_pStyleStruct->m_TexString = utf16_to_utf8(TexStr).c_str();
		m_pStyleStruct->Release();
		CGraphic::GetInst()->CreateTexture(L"",  
			(SQRGUIStyleManager::GetInst()->GetActiveStyle()->GetTexturePath()+utf16_to_utf8(TexStr)).c_str(),
			&(m_pStyleStruct->pTexture) );
		m_TextureEdit.SetWindowText(TexStr.c_str());
		RefreshMaskList();
	}
}
Ejemplo n.º 3
0
void win32_windowed_app_setup_params::trace_dump() const {
    TRACE("hinstance : {:x}", (unsigned int)get_hinstance());
    TRACE("window_class_name : {}", utf16_to_utf8(get_window_class_name()));
    TRACE("window_caption : {}", utf16_to_utf8(get_window_caption()));
    TRACE("min_window_size : {}", get_min_window_size());
    TRACE("small_icon_id : {}", get_small_icon_id());
    TRACE("large_icon_id : {}", get_large_icon_id());
    TRACE("is_visible_by_default : {}", bool_to_string(get_is_visible_by_default()));
}
Ejemplo n.º 4
0
const char* CBaseScriptApp::GetXMLFilePath(const char* szRelaFilePath) const
{
	if ( !szRelaFilePath )
		m_szXMLFilePath = utf16_to_utf8(m_pXMLPathMgr->GetFullPath(NULL));
	else
		m_szXMLFilePath = utf16_to_utf8(m_pXMLPathMgr->GetFullPath(utf8_to_utf16(szRelaFilePath).c_str()));

	return m_szXMLFilePath.c_str();
}
Ejemplo n.º 5
0
//------------------------------------------------------------------------------
CPostEffectLoader::CPostEffectLoader( const string& fileName )
{
	// load xml file
	wstring path = CGraphic::GetInst()->GetShaderConfigPath();
	path.append(utf8_to_utf16(fileName));
	ipkgstream stream;
	if ( stream.open(PATH_ALIAS_SHD.c_str(), utf16_to_utf8(path).c_str()) != 0 )
		GenErr( GraphicErr::GetErrTypeStr(ShaderInit_Err), "can't open " + utf16_to_utf8(path) );

	pPostEffectCfg = new CXmlConfig( "PostProcess" , stream );
	xmlConfig = pPostEffectCfg->GetRootNode();
}
Ejemplo n.º 6
0
int utf16_to_utf8_alloc(void **d,short *s)

{
    int len;
    char *d8;
    static char *funcname="utf16_to_utf8_alloc";

    (*d)=NULL;
    len=utf16_to_utf8(NULL,s,-1);
    willus_mem_alloc_warn(d,len+1,funcname,10);
    d8=(char *)(*d);
    utf16_to_utf8(d8,s,len);
    return(len);
}
Ejemplo n.º 7
0
void init_commandline_arguments_utf8(int *argc, char ***argv)
{
	int i, nArgs;
	LPWSTR *szArglist;

	szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);

	if(NULL == szArglist)
	{
		fprintf(stderr, "\nFATAL: CommandLineToArgvW failed\n\n");
		exit(-1);
	}

	*argv = (char**) malloc(sizeof(char*) * nArgs);
	*argc = nArgs;

	if(NULL == *argv)
	{
		fprintf(stderr, "\nFATAL: Malloc failed\n\n");
		exit(-1);
	}
	
	for(i = 0; i < nArgs; i++)
	{
		(*argv)[i] = utf16_to_utf8(szArglist[i]);
		if(NULL == (*argv)[i])
		{
			fprintf(stderr, "\nFATAL: utf16_to_utf8 failed\n\n");
			exit(-1);
		}
	}

	LocalFree(szArglist);
}
Ejemplo n.º 8
0
Archivo: env.c Proyecto: phodge/neovim
/// Gets the hostname of the current machine.
///
/// @param hostname   Buffer to store the hostname.
/// @param size       Size of `hostname`.
void os_get_hostname(char *hostname, size_t size)
{
#ifdef HAVE_SYS_UTSNAME_H
  struct utsname vutsname;

  if (uname(&vutsname) < 0) {
    *hostname = '\0';
  } else {
    xstrlcpy(hostname, vutsname.nodename, size);
  }
#elif defined(WIN32)
  wchar_t host_utf16[MAX_COMPUTERNAME_LENGTH + 1];
  DWORD host_wsize = sizeof(host_utf16) / sizeof(host_utf16[0]);
  if (GetComputerNameW(host_utf16, &host_wsize) == 0) {
    *hostname = '\0';
    DWORD err = GetLastError();
    EMSG2("GetComputerNameW failed: %d", err);
    return;
  }
  host_utf16[host_wsize] = '\0';

  char *host_utf8;
  int conversion_result = utf16_to_utf8(host_utf16, &host_utf8);
  if (conversion_result != 0) {
    EMSG2("utf16_to_utf8 failed: %d", conversion_result);
    return;
  }
  xstrlcpy(hostname, host_utf8, size);
  xfree(host_utf8);
#else
  EMSG("os_get_hostname failed: missing uname()");
  *hostname = '\0';
#endif
}
Ejemplo n.º 9
0
static void swkbdMessageCallback(void* user, NS_APPID sender, void* msg, size_t msgsize)
{
	SwkbdExtra* extra = (SwkbdExtra*)user;
	SwkbdState* swkbd = (SwkbdState*)msg;

	if (sender != APPID_SOFTWARE_KEYBOARD || msgsize != sizeof(SwkbdState))
		return;

	u16* text16 = (u16*)(swkbdSharedMem + swkbd->text_offset);
	ssize_t units = utf16_to_utf8(NULL, text16, 0);
	if (units < 0) svcBreak(USERBREAK_PANIC); // Shouldn't happen.
	char* text8 = (char*)malloc(units+1);
	if (!text8) svcBreak(USERBREAK_PANIC); // Shouldn't happen.
	swkbdConvertToUTF8(text8, text16, units);

	const char* retmsg = NULL;
	swkbd->callback_result = extra->callback(extra->callback_user, &retmsg, text8, units);
	if (swkbd->callback_result > SWKBD_CALLBACK_OK)
		swkbdConvertToUTF16(swkbd->callback_msg, retmsg, SWKBD_MAX_CALLBACK_MSG_LEN);
	else
		swkbd->callback_msg[0] = 0;

	free(text8);
	APT_SendParameter(envGetAptAppId(), sender, APTCMD_MESSAGE, swkbd, sizeof(*swkbd), 0);
}
Ejemplo n.º 10
0
void CRenderFont::DrawText( const RenderTextParam& param )
{
	if (wcslen(param.GetText())==0)
		return;
	this->realFont->SetAlignToPixel(m_bAlignToPixel);
	this->realFont->Resize(param.GetSize());
	this->Begin();

#ifdef CATCH_DRAWTEXT_EXCEPTION
	SQR_TRY
	{
		this->realFont->DrawText(param);
	}
	SQR_CATCH(exp)
	{
		exp.AppendMsg(" - realFont->DrawText(param) евакрЛЁё\n");
		const wstring drawText = param.GetText();
		const string u8drawText = utf16_to_utf8(drawText.c_str());
		exp.AppendMsg(u8drawText.c_str());
		GfkLogExp(exp);
	}
	SQR_TRY_END
#else
	this->realFont->DrawText(param);
#endif

	this->End();
}
Ejemplo n.º 11
0
static int read_usec(sd_id128_t vendor, const char *name, usec_t *u) {
        _cleanup_free_ void *i = NULL;
        _cleanup_free_ char *j = NULL;
        size_t is;
        int r;
        uint64_t x;

        assert(name);
        assert(u);

        r = efi_get_variable(EFI_VENDOR_LOADER, name, NULL, &i, &is);
        if (r < 0)
                return r;

        j = utf16_to_utf8(i, is);
        if (!j)
                return -ENOMEM;

        r = safe_atou64(j, &x);
        if (r < 0)
                return r;

        *u = x;
        return 0;
}
Ejemplo n.º 12
0
int efi_get_loader_device_part_uuid(sd_id128_t *u) {
        _cleanup_free_ void *s = NULL;
        _cleanup_free_ char *p = NULL;
        size_t ss;
        int r, parsed[16];
        unsigned i;

        assert(u);

        r = efi_get_variable(EFI_VENDOR_LOADER, "LoaderDevicePartUUID", NULL, &s, &ss);
        if (r < 0)
                return r;

        p = utf16_to_utf8(s, ss);
        if (!p)
                return -ENOMEM;

        if (sscanf(p, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
                   &parsed[0], &parsed[1], &parsed[2], &parsed[3],
                   &parsed[4], &parsed[5], &parsed[6], &parsed[7],
                   &parsed[8], &parsed[9], &parsed[10], &parsed[11],
                   &parsed[12], &parsed[13], &parsed[14], &parsed[15]) != 16)
                return -EIO;

        for (i = 0; i < ELEMENTSOF(parsed); i++)
                u->bytes[i] = parsed[i];

        return 0;
}
Ejemplo n.º 13
0
void CWndStyleEditor::OnBnClickedStyleOk()
{
	// TODO: Add your control notification handler code here
	CString str;
	m_StylesList.GetWindowText(str);
	SQRGUIStyle* pStyle = SQRGUIStyleManager::GetInst()->ActiveStyle(utf16_to_utf8(str.GetBuffer()).c_str());
	( ( ::CButton* )GetDlgItem( IDC_ABUTTON ) )		->SetCheck( 0 ) ;
	( ( ::CButton* )GetDlgItem( IDC_ACHECKBUTTON ) )->SetCheck( 0 ) ;
	( ( ::CButton* )GetDlgItem( IDC_ACOMBOBOX ) )	->SetCheck( 0 ) ;
	( ( ::CButton* )GetDlgItem( IDC_AEDIT ) )		->SetCheck( 0 ) ;
	( ( ::CButton* )GetDlgItem( IDC_ARICHTEXT ) )	->SetCheck( 0 ) ;
	( ( ::CButton* )GetDlgItem( IDC_APROGRESS ) )	->SetCheck( 0 ) ;
	( ( ::CButton* )GetDlgItem( IDC_ASCROLLBAR ) )	->SetCheck( 0 ) ;
	( ( ::CButton* )GetDlgItem( IDC_ASPIN ) )		->SetCheck( 0 ) ;
	( ( ::CButton* )GetDlgItem( IDC_ASTATIC ) )		->SetCheck( 0 ) ;
	( ( ::CButton* )GetDlgItem( IDC_ALISTCTRL ) )	->SetCheck( 0 ) ;
	( ( ::CButton* )GetDlgItem( IDC_ATREECTRL ) )	->SetCheck( 0 ) ;
	( ( ::CButton* )GetDlgItem( IDC_AWNDMOVE ) )	->SetCheck( 0 ) ;
	( ( ::CButton* )GetDlgItem( IDC_CLOCK ) )		->SetCheck( 0 ) ;
	( ( ::CButton* )GetDlgItem( IDC_CHART ) )		->SetCheck( 0 ) ;
	( ( ::CButton* )GetDlgItem( IDC_AICON2 ) )		->SetCheck( 0 ) ;
	( ( ::CButton* )GetDlgItem( IDC_CWnd ) )		->SetCheck( 1 ) ;
	OnBnClickedCWnd();
	RefreshMaskList();
}
Ejemplo n.º 14
0
void CBaseScriptApp::ConfigSearchPath()
{
	const char DEFAULT_SEARCH_PATH_NODE[128] = "default";

	// 加载搜索路径配置文件
	CXmlConfig* pXmlDirectory = LoadCfgFile( "etc/common/Directory.xml", "directory" );
	string setting_path = pXmlDirectory->Get<string>(DEFAULT_SEARCH_PATH_NODE, "setting_path");
	string xml_path = pXmlDirectory->Get<string>(DEFAULT_SEARCH_PATH_NODE, "xml_path");
	string gui_path = pXmlDirectory->Get<string>(DEFAULT_SEARCH_PATH_NODE, "gui_path");
	string lang_path = pXmlDirectory->Get<string>(DEFAULT_SEARCH_PATH_NODE, "lang_path");
	string res_path = pXmlDirectory->Get<string>(DEFAULT_SEARCH_PATH_NODE, "res_path");

	AddLoadPath("cfg", setting_path, true);
	AddLoadPath("gui", gui_path, false);
	AddLoadPath("res", res_path, false);
	AddLoadPath("lan", lang_path, false);
	AddLoadPath("shd", utf16_to_utf8(m_pRootPathMgr->GetRootPath()).c_str(), false);

	// 创建各路径管理器
	m_pCfgPathMgr	= new CPathMgr( setting_path.c_str() );
	m_pXMLPathMgr	= new CPathMgr( xml_path.c_str() );
	m_pGUIPathMgr	= new CPathMgr( gui_path.c_str() );
	m_pLangPathMgr	= new CPathMgr( lang_path.c_str() );
	m_pResPathMgr	= new CPathMgr();
	m_pResPathMgr->SetCurPath( utf8_to_utf16(res_path).c_str() );

	SafeDelete(pXmlDirectory);	
}
Ejemplo n.º 15
0
static gchar* convertUniCharToUTF8(const UChar* characters, gint length, int from, int to)
{
    gchar* utf8 = 0;
    gint new_length = 0;
    utf16_to_utf8(characters, length, utf8, new_length);
    if (!utf8)
        return NULL;

    if (from > 0) {
        // discard the first 'from' characters
        // FIXME: we should do this before the conversion probably
        gchar* str_left = g_utf8_offset_to_pointer(utf8, from);
        gchar* tmp = g_strdup(str_left);
        g_free(utf8);
        utf8 = tmp;
    }

    gchar* pos = utf8;
    gint len = strlen(pos);
    GString* ret = g_string_new_len(NULL, len);

    // replace line break by space
    while (len > 0) {
        gint index, start;
        pango_find_paragraph_boundary(pos, len, &index, &start);
        g_string_append_len(ret, pos, index);
        if (index == start)
            break;
        g_string_append_c(ret, ' ');
        pos += start;
        len -= start;
    }
    return g_string_free(ret, FALSE);
}
Ejemplo n.º 16
0
bool ComputeHash_FromText(const int hashType, const TCHAR *const textData, TCHAR *const hashOut, const size_t hashOutSize)
{
	const size_t hashSize = GetHashSize(hashType);
	if((hashSize == SIZE_MAX) || (hashSize >= (hashOutSize / 2)))
	{
		if(hashSize != SIZE_MAX) ERROR_MSG(T("Output buffer is too small to hold the hash value!"));
		return false;
	}

	hash_ctx ctx;
	if(!HashFunction_Init(hashType, &ctx))
	{
		return false;
	}

#ifdef UNICODE
	const char *const textUtf8 = utf16_to_utf8(textData);
	if(textUtf8 == NULL)
	{
		return false;
	}
	HashFunction_Update(&ctx, (BYTE*)textUtf8, strlen(textUtf8));
	delete [] textUtf8;
#else
	HashFunction_Update(&ctx, (BYTE*)textData, strlen(textData));
#endif

	BYTE hashValue[128];
	HashFunction_Final(&ctx, hashValue);
	ConvertHashToHex(hashSize, hashValue, hashOut);
	return true;
};
Ejemplo n.º 17
0
static void
XAUDIO2_DetectDevices(int iscapture, SDL_AddAudioDevice addfn)
{
    IXAudio2 *ixa2 = NULL;
    UINT32 devcount = 0;
    UINT32 i = 0;
    void *ptr = NULL;

    if (iscapture) {
        SDL_SetError("XAudio2: capture devices unsupported.");
        return;
    } else if (XAudio2Create(&ixa2, 0, XAUDIO2_DEFAULT_PROCESSOR) != S_OK) {
        SDL_SetError("XAudio2: XAudio2Create() failed.");
        return;
    } else if (IXAudio2_GetDeviceCount(ixa2, &devcount) != S_OK) {
        SDL_SetError("XAudio2: IXAudio2::GetDeviceCount() failed.");
        IXAudio2_Release(ixa2);
        return;
    }

    for (i = 0; i < devcount; i++) {
        XAUDIO2_DEVICE_DETAILS details;
        if (IXAudio2_GetDeviceDetails(ixa2, i, &details) == S_OK) {
            char *str = utf16_to_utf8(details.DisplayName);
            if (str != NULL) {
                addfn(str);
                SDL_free(str);  /* addfn() made a copy of the string. */
            }
        }
    }

    IXAudio2_Release(ixa2);
}
Ejemplo n.º 18
0
static const char* _vd3deName(struct VDirEntry* vde) {
	struct VDirEntry3DS* vd3de = (struct VDirEntry3DS*) vde;
	if (!vd3de->utf8Name[0]) {
		utf16_to_utf8((uint8_t*) vd3de->utf8Name, vd3de->ent.name, sizeof(vd3de->utf8Name));
	}
	return vd3de->utf8Name;
}
Ejemplo n.º 19
0
/* Strings, CS0 (UDF 2.1.1) */
static char *_cs0_to_utf8(const uint8_t *cs0, size_t size)
{
    size_t   out_pos = 0;
    size_t   out_size = size;
    size_t   i;
    uint8_t *out = (uint8_t *)malloc(size);

    if (!out) {
        udf_error("out of memory\n");
        return NULL;
    }

    switch (cs0[0]) {
    case 8:
        /*udf_trace("string in utf-8\n");*/
        for (i = 1; i < size; i++) {
            utf16lo_to_utf8(out, out_pos, out_size, cs0[i]);
        }
        break;
    case 16:
        for (i = 1; i < size; i+=2) {
            uint16_t ch = cs0[i + 1] | (cs0[i] << 8);
            utf16_to_utf8(out, out_pos, out_size, ch);
        }
        break;
    default:
        udf_error("unregonized string encoding %u\n", cs0[0]);
        free(out);
        return NULL;
    }

    out[out_pos] = 0;
    return (char*)out;
}
Ejemplo n.º 20
0
void CWndStyleEditor::OnBnClickedStyleDel()
{
	// TODO: Add your control notification handler code here
	CString str;
	m_StylesList.GetWindowText(str);
	SQRGUIStyleManager::GetInst()->DelStyle(utf16_to_utf8(str.GetBuffer()).c_str());
	RefreshList();
}
Ejemplo n.º 21
0
void CBaseScriptApp::ChangeCurPathToRes()
{
#ifdef _WIN32
	_wchdir(m_pResPathMgr->GetCurPath());
#else
	chdir( utf16_to_utf8(m_pResPathMgr->GetCurPath()).c_str() );
#endif
}
Ejemplo n.º 22
0
static Value wstr_to_file(RefStr *base_dir, const wchar_t *wp, int size)
{
    int fname_len = utf16_to_utf8(NULL, wp, size);
    int basedir_last_sep = (base_dir->c[base_dir->size - 1] == SEP_C);
    int total_len = base_dir->size + (basedir_last_sep ? 0 : 1) + fname_len;
    RefStr *rs_name = fs->refstr_new_n(fs->cls_file, total_len);
    char *dst = rs_name->c;

    memcpy(dst, base_dir->c, base_dir->size);
    dst += base_dir->size;
    if (!basedir_last_sep) {
        *dst++ = SEP_C;
    }
    utf16_to_utf8(dst, wp, size);

    return vp_Value(rs_name);
}
Ejemplo n.º 23
0
	//-----------------------------------------------------------------//
	inline strings strings_to_strings(const wstrings& src) noexcept {
		strings dst;
		for(const auto& ws : src) {
			auto tmp = utf16_to_utf8(ws);
			dst.push_back(tmp);
		}
		return dst;
	}
Ejemplo n.º 24
0
static int task_populate_files_compare_directory_entries(const void* e1, const void* e2) {
    FS_DirectoryEntry* ent1 = (FS_DirectoryEntry*) e1;
    FS_DirectoryEntry* ent2 = (FS_DirectoryEntry*) e2;

    if((ent1->attributes & FS_ATTRIBUTE_DIRECTORY) && !(ent2->attributes & FS_ATTRIBUTE_DIRECTORY)) {
        return -1;
    } else if(!(ent1->attributes & FS_ATTRIBUTE_DIRECTORY) && (ent2->attributes & FS_ATTRIBUTE_DIRECTORY)) {
        return 1;
    } else {
        char entryName1[0x213] = {'\0'};
        utf16_to_utf8((uint8_t*) entryName1, ent1->name, sizeof(entryName1) - 1);

        char entryName2[0x213] = {'\0'};
        utf16_to_utf8((uint8_t*) entryName2, ent2->name, sizeof(entryName2) - 1);

        return strcasecmp(entryName1, entryName2);
    }
}
Ejemplo n.º 25
0
static std::string get_string_from_utf16(const char16_t* input, int input_len) {
    ssize_t utf8_length = utf16_to_utf8_length(input, input_len);
    if (utf8_length <= 0) {
        return {};
    }
    std::string utf8;
    utf8.resize(utf8_length);
    utf16_to_utf8(input, input_len, &*utf8.begin(), utf8_length + 1);
    return utf8;
}
Ejemplo n.º 26
0
Result udsGetNodeInfoUsername(const udsNodeInfo *nodeinfo, char *username)
{
	ssize_t units=0;
	size_t len = 10;

	units = utf16_to_utf8((uint8_t*)username, (uint16_t*)nodeinfo->username, len);

	if(units < 0 || units > len)return -2;
	return 0;
}
Ejemplo n.º 27
0
static GtkWidget *
vcard_get_preview (EImport *ei,
                   EImportTarget *target,
                   EImportImporter *im)
{
	GtkWidget *preview;
	GSList *contacts;
	gchar *contents;
	VCardEncoding encoding;
	EImportTargetURI *s = (EImportTargetURI *) target;
	gchar *filename;

	filename = g_filename_from_uri (s->uri_src, NULL, NULL);
	if (filename == NULL) {
		g_message (G_STRLOC ": Couldn't get filename from URI '%s'", s->uri_src);
		return NULL;
	}

	encoding = guess_vcard_encoding (filename);
	if (encoding == VCARD_ENCODING_NONE) {
		g_free (filename);
		return NULL;
	}

	if (!g_file_get_contents (filename, &contents, NULL, NULL)) {
		g_message (G_STRLOC ": Couldn't read file.");
		g_free (filename);
		return NULL;
	}

	g_free (filename);

	if (encoding == VCARD_ENCODING_UTF16) {
		gchar *tmp;

		gunichar2 *contents_utf16 = (gunichar2 *) contents;
		tmp = utf16_to_utf8 (contents_utf16);
		g_free (contents);
		contents = tmp;
	} else if (encoding == VCARD_ENCODING_LOCALE) {
		gchar *tmp;
		tmp = g_locale_to_utf8 (contents, -1, NULL, NULL, NULL);
		g_free (contents);
		contents = tmp;
	}

	contacts = eab_contact_list_from_string (contents);
	g_free (contents);

	preview = evolution_contact_importer_get_preview_widget (contacts);

	e_client_util_free_object_slist (contacts);

	return preview;
}
Ejemplo n.º 28
0
static void test_utf16_to_utf8(void) {
        char *a = NULL;
        const uint16_t utf16[] = { htole16('a'), htole16(0xd800), htole16('b'), htole16(0xdc00), htole16('c'), htole16(0xd801), htole16(0xdc37) };
        const char utf8[] = { 'a', 'b', 'c', 0xf0, 0x90, 0x90, 0xb7, 0 };

        a = utf16_to_utf8(utf16, 14);
        assert_se(a);
        assert_se(streq(a, utf8));

        free(a);
}
Ejemplo n.º 29
0
std::string utf16ToUtf8(const StringPiece16& utf16) {
    ssize_t utf8Length = utf16_to_utf8_length(utf16.data(), utf16.length());
    if (utf8Length <= 0) {
        return {};
    }

    std::string utf8;
    utf8.resize(utf8Length);
    utf16_to_utf8(utf16.data(), utf16.length(), &*utf8.begin());
    return utf8;
}
Ejemplo n.º 30
0
void CWndStyleEditor::OnBnClickedStyleAdd()
{
	// TODO: Add your control notification handler code here
	CString str;
	m_StylesList.GetWindowText(str);
	SQRGUIStyleManager::GetInst()->AddStyle(utf16_to_utf8(str.GetBuffer()).c_str());

	CString path = L"..\\gui\\style\\" + str;
	_wmkdir(path.GetBuffer());
	RefreshList();
}