jscript: Added jsstr_extract helper and use it in String.charCodeAt implementation.
This commit is contained in:
parent
41d3085522
commit
618b88ef30
|
@ -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));
|
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)
|
static inline unsigned jsstr_flush(jsstr_t *str, WCHAR *buf)
|
||||||
{
|
{
|
||||||
unsigned len = jsstr_length(str);
|
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)
|
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;
|
int jsstr_cmp(jsstr_t*,jsstr_t*) DECLSPEC_HIDDEN;
|
||||||
|
|
|
@ -347,8 +347,11 @@ static HRESULT String_charCodeAt(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
|
||||||
idx = d;
|
idx = d;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(r)
|
if(r) {
|
||||||
*r = jsval_number(str->str[idx]);
|
WCHAR c;
|
||||||
|
jsstr_extract(str, idx, 1, &c);
|
||||||
|
*r = jsval_number(c);
|
||||||
|
}
|
||||||
|
|
||||||
jsstr_release(str);
|
jsstr_release(str);
|
||||||
return S_OK;
|
return S_OK;
|
||||||
|
|
Loading…
Reference in New Issue