jscript: Added jsstr_extract helper and use it in String.charCodeAt implementation.

This commit is contained in:
Jacek Caban 2013-03-28 11:01:52 +01:00 committed by Alexandre Julliard
parent 41d3085522
commit 618b88ef30
2 changed files with 17 additions and 3 deletions

View File

@ -65,6 +65,11 @@ 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 void jsstr_extract(jsstr_t *str, unsigned off, unsigned len, WCHAR *buf)
{
memcpy(buf, str->str+off, len*sizeof(WCHAR));
}
static inline unsigned jsstr_flush(jsstr_t *str, WCHAR *buf)
{
unsigned len = jsstr_length(str);
@ -74,7 +79,13 @@ static inline unsigned jsstr_flush(jsstr_t *str, WCHAR *buf)
static inline jsstr_t *jsstr_substr(jsstr_t *str, unsigned off, unsigned len)
{
return jsstr_alloc_len(str->str+off, len);
jsstr_t *ret;
WCHAR *ptr;
ptr = jsstr_alloc_buf(len, &ret);
if(ptr)
jsstr_extract(str, off, len, ptr);
return ret;
}
int jsstr_cmp(jsstr_t*,jsstr_t*) DECLSPEC_HIDDEN;

View File

@ -347,8 +347,11 @@ static HRESULT String_charCodeAt(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
idx = d;
}
if(r)
*r = jsval_number(str->str[idx]);
if(r) {
WCHAR c;
jsstr_extract(str, idx, 1, &c);
*r = jsval_number(c);
}
jsstr_release(str);
return S_OK;