Prima
view release on metacpan or search on metacpan
win32/misc.c view on Meta::CPAN
else
res = false;
}
RegCloseKey( hKey);
FINALIZE:
i = 2;
while( i--) {
list_delete_all( &ids[i], true);
list_destroy( &ids[i]);
}
return res;
}
Bool
apc_dl_export(char *path)
{
return LoadLibrary( path) != NULL;
}
WCHAR *
alloc_utf8_to_wchar( const char * utf8, int length, int * mb_len)
{
WCHAR * ret;
int size;
char * u2 = (char*) utf8;
if ( length > 0) {
while ( length-- > 0 ) u2 = ( char*) utf8_hop(( U8*) u2, 1);
length = u2 - utf8;
}
size = MultiByteToWideChar(CP_UTF8, 0, utf8, length, NULL, 0);
if ( size < 0) {
if ( mb_len ) *mb_len = 0;
return NULL;
}
if ( !( ret = malloc( size * sizeof( WCHAR)))) return NULL;
MultiByteToWideChar(CP_UTF8, 0, utf8, length, ret, size);
if ( mb_len ) *mb_len = size;
return ret;
}
WCHAR *
alloc_utf8_to_wchar_visual( const char * utf8, int length, int * mb_len)
{
WCHAR * ret;
int i, size;
char * u2 = (char*) utf8;
if ( length > 0) {
while ( length-- > 0 ) u2 = ( char*) utf8_hop(( U8*) u2, 1);
length = u2 - utf8;
}
size = MultiByteToWideChar(CP_UTF8, 0, utf8, length, NULL, 0);
if ( size < 0) {
if ( mb_len ) *mb_len = 0;
return NULL;
}
if ( !( ret = malloc((size + 1) * sizeof( WCHAR)))) return NULL;
/*
U+202A (LRE) LEFT-TO-RIGHT EMBEDDING Treats the following text as embedded left-to-right.
U+202B (RLE) RIGHT-TO-LEFT EMBEDDING Treats the following text as embedded right to left.
U+202D (LRO) LEFT-TO-RIGHT OVERRIDE Forces the following characters to be treated as strong left-to-right characters.
U+202E (RLO) RIGHT-TO-LEFT OVERRIDE Forces the following characters to be treated as strong right-to-left characters.
U+202C (PDF) POP DIRECTIONAL FORMATTING CODE Restores the bidirectional state to what it was before the last LRE, RLE, RLO, or LRO.
U+200E (LRM) LEFT-TO-RIGHT MARK Left-to-right strong zero-width character.
U+200F (RLM) RIGHT-TO-LEFT MARK Right-to-left strong zero-width character.
*/
ret[0] = 0x202D;
MultiByteToWideChar(CP_UTF8, 0, utf8, length, ret + 1, size);
for ( i = 1; i < size + 1; i++) {
if (( ret[i] >= 0x202A && ret[i] <= 0x202E) || ret[i] == 0x200F )
ret[i] = 0x200E;
}
if ( mb_len ) *mb_len = size + 1;
return ret;
}
void
wchar2char( char * dest, WCHAR * src, int lim)
{
if ( lim < 1) return;
while ( lim-- && *src) *(dest++) = *((char*)src++);
if ( lim < 0) dest--;
*dest = 0;
}
void
char2wchar( WCHAR * dest, char * src, int lim)
{
int l = strlen( src) + 1;
if ( lim < 0) lim = l;
if ( lim == 0) return;
if ( lim > l) lim = l;
src += lim - 2;
dest += lim - 1;
*(dest--) = 0;
while ( --lim) *(dest--) = *(src--);
}
WCHAR *
alloc_ascii_to_wchar( const char * text, int *length)
{
WCHAR * ret;
int src_len, dst_len;
src_len = length ? *length : -1;
if ( length )
*length = 0;
if ( text == NULL || src_len == 0 )
return NULL;
if ( src_len < 0)
src_len = strlen( text) + 1;
if ( ( dst_len = MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, text, src_len, NULL, 0)) <= 0)
return NULL;
if ( length )
*length = dst_len;
if ( !( ret = malloc( dst_len * sizeof( WCHAR)))) return NULL;
MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, text, src_len, ret, dst_len * 2);
return ret;
}
( run in 1.103 second using v1.01-cache-2.11-cpan-71847e10f99 )