Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libs/fmt/fmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ static void md5_finish( md5_context *ctx, uint8 digest[16] ) {

HL_PRIM void HL_NAME(digest)( vbyte *out, vbyte *in, int length, int format ) {
if( format & 256 ) {
in = (vbyte*)hl_to_utf8((uchar*)in);
in = (vbyte*)hl_to_utf8_len((uchar*)in, length);
length = (int)strlen((char*)in);
}
hl_blocking(true);
Expand Down
1 change: 1 addition & 0 deletions src/hl.h
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,7 @@ HL_API vbyte *hl_copy_bytes( const vbyte *byte, int size );
HL_API int hl_utf8_length( const vbyte *s, int pos );
HL_API int hl_from_utf8( uchar *out, int outLen, const char *str );
HL_API char *hl_to_utf8( const uchar *bytes );
HL_API char *hl_to_utf8_len( const uchar *bytes, int len );
HL_API uchar *hl_to_utf16( const char *str );
HL_API uchar *hl_guid_str( int64 guid, uchar buf[14] );
HL_API vdynamic *hl_virtual_make_value( vvirtual *v );
Expand Down
2 changes: 1 addition & 1 deletion src/std/date.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ HL_PRIM int hl_date_from_time( double time ) {
HL_PRIM int hl_date_from_string( vbyte *b, int len ) {
struct tm t;
int o = 0;
const char *str = hl_to_utf8((uchar*)b);
const char *str = hl_to_utf8_len((uchar*)b, len);
bool recal = true;
memset(&t,0,sizeof(struct tm));
switch( strlen(str) ) {
Expand Down
9 changes: 7 additions & 2 deletions src/std/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ HL_PRIM vbyte *hl_utf16_to_utf8( vbyte *str, int len, int *size ) {
uchar *end = len == 0 ? NULL : c + len;
int utf8bytes = 0;
int p = 0;
while( c != end ) {
while( c < end ) {
unsigned int v = (unsigned int)*c;
if( v == 0 && end == NULL ) break;
if( v < 0x80 )
Expand All @@ -216,7 +216,7 @@ HL_PRIM vbyte *hl_utf16_to_utf8( vbyte *str, int len, int *size ) {
}
out = hl_gc_alloc_noptr(utf8bytes + 1);
c = (uchar*)str;
while( c != end ) {
while( c < end ) {
unsigned int v = (unsigned int)*c;
if( v < 0x80 ) {
out[p++] = (vbyte)v;
Expand Down Expand Up @@ -246,6 +246,11 @@ HL_PRIM char *hl_to_utf8( const uchar *bytes ) {
return (char*)hl_utf16_to_utf8((vbyte*)bytes, 0, &size);
}

HL_PRIM char *hl_to_utf8_len( const uchar *bytes, int len ) {
int size;
return (char*)hl_utf16_to_utf8((vbyte*)bytes, len, &size);
}

static void hl_buffer_hex( hl_buffer *b, int c ) {
static const uchar *hex = USTR("0123456789ABCDEF");
hl_buffer_char(b,'%');
Expand Down