diff --git a/dlls/vbscript/global.c b/dlls/vbscript/global.c index fa600ee52dd..e6211b7f73a 100644 --- a/dlls/vbscript/global.c +++ b/dlls/vbscript/global.c @@ -864,8 +864,30 @@ static HRESULT Global_RTrim(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VAR static HRESULT Global_Trim(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res) { - FIXME("\n"); - return E_NOTIMPL; + BSTR str, conv_str = NULL; + WCHAR *begin_ptr, *end_ptr; + HRESULT hres; + + TRACE("%s\n", debugstr_variant(arg)); + + if(V_VT(arg) == VT_BSTR) { + str = V_BSTR(arg); + }else { + hres = to_string(arg, &conv_str); + if(FAILED(hres)) + return hres; + str = conv_str; + } + + for(begin_ptr = str; *begin_ptr && isspaceW(*begin_ptr); begin_ptr++); + for(end_ptr = str+SysStringLen(str); end_ptr-1 > begin_ptr && isspaceW(*(end_ptr-1)); end_ptr--); + + str = SysAllocStringLen(begin_ptr, end_ptr-begin_ptr); + SysFreeString(conv_str); + if(!str) + return E_OUTOFMEMORY; + + return return_bstr(res, str); } static HRESULT Global_Space(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res) diff --git a/dlls/vbscript/tests/api.vbs b/dlls/vbscript/tests/api.vbs index 06122ef70b3..7553d59243f 100644 --- a/dlls/vbscript/tests/api.vbs +++ b/dlls/vbscript/tests/api.vbs @@ -225,6 +225,18 @@ TestRight "test", 0, "" TestRight 123, 2, "23" if isEnglishLang then TestRight true, 2, "ue" +Sub TestTrim(str, exstr) + Call ok(Trim(str) = exstr, "Trim(" & str & ") = " & Trim(str)) +End Sub + +TestTrim " test ", "test" +TestTrim "test ", "test" +TestTrim " test", "test" +TestTrim "test", "test" +TestTrim "", "" +TestTrim 123, "123" +if isEnglishLang then TestTrim true, "True" + Sub TestRound(val, exval, vt) Call ok(Round(val) = exval, "Round(" & val & ") = " & Round(val)) Call ok(getVT(Round(val)) = vt, "getVT(Round(" & val & ")) = " & getVT(Round(val)))