jscript: Added jsstr_flush helper and use it in array_join.

This commit is contained in:
Jacek Caban 2013-03-05 11:48:55 +01:00 committed by Alexandre Julliard
parent 0effd926b6
commit 29ff14493d
2 changed files with 11 additions and 13 deletions

View File

@ -286,15 +286,10 @@ static HRESULT array_join(script_ctx_t *ctx, jsdisp_t *array, DWORD length, cons
if(SUCCEEDED(hres))
ret = jsstr_alloc_buf(len);
if(ret) {
unsigned tmplen;
ptr = ret->str;
if(str_tab[0]) {
tmplen = jsstr_length(str_tab[0]);
memcpy(ptr, str_tab[0]->str, tmplen*sizeof(WCHAR));
ptr += tmplen;
}
if(str_tab[0])
ptr += jsstr_flush(str_tab[0], ptr);
for(i=1; i < length; i++) {
if(seplen) {
@ -302,13 +297,9 @@ static HRESULT array_join(script_ctx_t *ctx, jsdisp_t *array, DWORD length, cons
ptr += seplen;
}
if(str_tab[i]) {
tmplen = jsstr_length(str_tab[i]);
memcpy(ptr, str_tab[i]->str, tmplen*sizeof(WCHAR));
ptr += tmplen;
}
if(str_tab[i])
ptr += jsstr_flush(str_tab[i], ptr);
}
*ptr=0;
}else {
hres = E_OUTOFMEMORY;
}

View File

@ -59,6 +59,13 @@ static inline BOOL jsstr_eq(jsstr_t *str1, jsstr_t *str2)
return len == jsstr_length(str2) && !memcmp(str1->str, str2->str, len*sizeof(WCHAR));
}
static inline unsigned jsstr_flush(jsstr_t *str, WCHAR *buf)
{
unsigned len = jsstr_length(str);
memcpy(buf, str->str, len*sizeof(WCHAR));
return len;
}
static inline jsstr_t *jsstr_substr(jsstr_t *str, unsigned off, unsigned len)
{
return jsstr_alloc_len(str->str+off, len);