2014-12-15 08:24:48 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Martin Storsjo
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
2019-05-28 05:39:37 +00:00
|
|
|
#include <wchar.h>
|
2014-12-15 08:24:48 +00:00
|
|
|
|
|
|
|
#include "windows.h"
|
|
|
|
#include "winerror.h"
|
|
|
|
#include "hstring.h"
|
2015-10-25 14:32:15 +00:00
|
|
|
#include "wine/debug.h"
|
2014-12-15 08:24:48 +00:00
|
|
|
|
2015-10-25 14:32:15 +00:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(winstring);
|
2014-12-15 08:24:48 +00:00
|
|
|
|
2022-01-24 15:09:20 +00:00
|
|
|
#define HSTRING_REFERENCE_FLAG 1
|
|
|
|
|
|
|
|
struct hstring_header
|
|
|
|
{
|
|
|
|
UINT32 flags;
|
2022-01-24 15:09:21 +00:00
|
|
|
UINT32 length;
|
2022-01-24 15:09:22 +00:00
|
|
|
UINT32 padding1;
|
|
|
|
UINT32 padding2;
|
|
|
|
const WCHAR *str;
|
2022-01-24 15:09:20 +00:00
|
|
|
};
|
|
|
|
|
2014-12-15 08:24:48 +00:00
|
|
|
struct hstring_private
|
|
|
|
{
|
2022-01-24 15:09:20 +00:00
|
|
|
struct hstring_header header;
|
2022-01-24 15:09:23 +00:00
|
|
|
LONG refcount;
|
|
|
|
WCHAR buffer[1];
|
2014-12-15 08:24:48 +00:00
|
|
|
};
|
|
|
|
|
2014-12-15 08:24:49 +00:00
|
|
|
static const WCHAR empty[1];
|
|
|
|
|
2022-01-24 15:09:20 +00:00
|
|
|
C_ASSERT(sizeof(struct hstring_header) <= sizeof(HSTRING_HEADER));
|
2014-12-15 08:24:48 +00:00
|
|
|
|
|
|
|
static inline struct hstring_private *impl_from_HSTRING(HSTRING string)
|
|
|
|
{
|
2022-01-24 15:09:20 +00:00
|
|
|
return (struct hstring_private *)string;
|
2014-12-15 08:24:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct hstring_private *impl_from_HSTRING_HEADER(HSTRING_HEADER *header)
|
|
|
|
{
|
2022-01-24 15:09:20 +00:00
|
|
|
return CONTAINING_RECORD(header, struct hstring_private, header);
|
2014-12-15 08:24:48 +00:00
|
|
|
}
|
|
|
|
|
2014-12-15 08:24:50 +00:00
|
|
|
static inline struct hstring_private *impl_from_HSTRING_BUFFER(HSTRING_BUFFER buffer)
|
|
|
|
{
|
2022-01-24 15:09:20 +00:00
|
|
|
return CONTAINING_RECORD(buffer, struct hstring_private, buffer);
|
2014-12-15 08:24:50 +00:00
|
|
|
}
|
|
|
|
|
2014-12-15 08:24:48 +00:00
|
|
|
static BOOL alloc_string(UINT32 len, HSTRING *out)
|
|
|
|
{
|
|
|
|
struct hstring_private *priv;
|
2022-05-19 09:30:40 +00:00
|
|
|
priv = malloc(offsetof(struct hstring_private, buffer[len+1]));
|
2014-12-15 08:24:48 +00:00
|
|
|
if (!priv)
|
|
|
|
return FALSE;
|
2022-01-24 15:09:20 +00:00
|
|
|
|
|
|
|
priv->header.flags = 0;
|
2022-01-24 15:09:21 +00:00
|
|
|
priv->header.length = len;
|
2022-01-24 15:09:22 +00:00
|
|
|
priv->header.str = priv->buffer;
|
2022-01-24 15:09:23 +00:00
|
|
|
|
2014-12-15 08:24:48 +00:00
|
|
|
priv->refcount = 1;
|
|
|
|
priv->buffer[len] = '\0';
|
2022-01-24 15:09:20 +00:00
|
|
|
|
2014-12-15 08:24:48 +00:00
|
|
|
*out = (HSTRING)priv;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WindowsCreateString (combase.@)
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI WindowsCreateString(LPCWSTR ptr, UINT32 len,
|
|
|
|
HSTRING *out)
|
|
|
|
{
|
|
|
|
struct hstring_private *priv;
|
2015-10-25 14:32:15 +00:00
|
|
|
|
|
|
|
TRACE("(%s, %u, %p)\n", debugstr_wn(ptr, len), len, out);
|
|
|
|
|
2014-12-15 08:24:48 +00:00
|
|
|
if (out == NULL)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
if (len == 0)
|
|
|
|
{
|
|
|
|
*out = NULL;
|
|
|
|
return S_OK;
|
|
|
|
}
|
2015-10-25 14:32:26 +00:00
|
|
|
if (ptr == NULL)
|
|
|
|
return E_POINTER;
|
2014-12-15 08:24:48 +00:00
|
|
|
if (!alloc_string(len, out))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
priv = impl_from_HSTRING(*out);
|
|
|
|
memcpy(priv->buffer, ptr, len * sizeof(*priv->buffer));
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WindowsCreateStringReference (combase.@)
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI WindowsCreateStringReference(LPCWSTR ptr, UINT32 len,
|
|
|
|
HSTRING_HEADER *header, HSTRING *out)
|
|
|
|
{
|
|
|
|
struct hstring_private *priv = impl_from_HSTRING_HEADER(header);
|
2015-10-25 14:32:15 +00:00
|
|
|
|
|
|
|
TRACE("(%s, %u, %p, %p)\n", debugstr_wn(ptr, len), len, header, out);
|
|
|
|
|
2014-12-15 08:24:48 +00:00
|
|
|
if (out == NULL || header == NULL)
|
|
|
|
return E_INVALIDARG;
|
2015-10-29 08:21:22 +00:00
|
|
|
if (ptr != NULL && ptr[len] != '\0')
|
|
|
|
return E_INVALIDARG;
|
2014-12-15 08:24:48 +00:00
|
|
|
if (len == 0)
|
|
|
|
{
|
|
|
|
*out = NULL;
|
|
|
|
return S_OK;
|
|
|
|
}
|
2015-10-25 14:32:26 +00:00
|
|
|
if (ptr == NULL)
|
|
|
|
return E_POINTER;
|
2022-01-24 15:09:20 +00:00
|
|
|
|
2022-01-24 15:09:22 +00:00
|
|
|
priv->header.str = ptr;
|
2022-01-24 15:09:21 +00:00
|
|
|
priv->header.length = len;
|
2022-01-24 15:09:20 +00:00
|
|
|
priv->header.flags = HSTRING_REFERENCE_FLAG;
|
|
|
|
|
|
|
|
*out = (HSTRING)priv;
|
2014-12-15 08:24:48 +00:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WindowsDeleteString (combase.@)
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI WindowsDeleteString(HSTRING str)
|
|
|
|
{
|
|
|
|
struct hstring_private *priv = impl_from_HSTRING(str);
|
2015-10-25 14:32:15 +00:00
|
|
|
|
|
|
|
TRACE("(%p)\n", str);
|
|
|
|
|
2014-12-15 08:24:48 +00:00
|
|
|
if (str == NULL)
|
|
|
|
return S_OK;
|
2022-01-24 15:09:20 +00:00
|
|
|
if (priv->header.flags & HSTRING_REFERENCE_FLAG)
|
2014-12-15 08:24:48 +00:00
|
|
|
return S_OK;
|
|
|
|
if (InterlockedDecrement(&priv->refcount) == 0)
|
2022-05-19 09:30:40 +00:00
|
|
|
free(priv);
|
2014-12-15 08:24:48 +00:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WindowsDuplicateString (combase.@)
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI WindowsDuplicateString(HSTRING str, HSTRING *out)
|
|
|
|
{
|
|
|
|
struct hstring_private *priv = impl_from_HSTRING(str);
|
2015-10-25 14:32:15 +00:00
|
|
|
|
|
|
|
TRACE("(%p, %p)\n", str, out);
|
|
|
|
|
2014-12-15 08:24:48 +00:00
|
|
|
if (out == NULL)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
if (str == NULL)
|
|
|
|
{
|
|
|
|
*out = NULL;
|
|
|
|
return S_OK;
|
|
|
|
}
|
2022-01-24 15:09:20 +00:00
|
|
|
if (priv->header.flags & HSTRING_REFERENCE_FLAG)
|
2022-01-24 15:09:22 +00:00
|
|
|
return WindowsCreateString(priv->header.str, priv->header.length, out);
|
2014-12-15 08:24:48 +00:00
|
|
|
InterlockedIncrement(&priv->refcount);
|
|
|
|
*out = str;
|
|
|
|
return S_OK;
|
|
|
|
}
|
2014-12-15 08:24:49 +00:00
|
|
|
|
2014-12-15 08:24:50 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* WindowsPreallocateStringBuffer (combase.@)
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI WindowsPreallocateStringBuffer(UINT32 len, WCHAR **outptr,
|
|
|
|
HSTRING_BUFFER *out)
|
|
|
|
{
|
|
|
|
struct hstring_private *priv;
|
|
|
|
HSTRING str;
|
2015-10-25 14:32:15 +00:00
|
|
|
|
|
|
|
TRACE("(%u, %p, %p)\n", len, outptr, out);
|
|
|
|
|
2014-12-15 08:24:50 +00:00
|
|
|
if (outptr == NULL || out == NULL)
|
|
|
|
return E_POINTER;
|
|
|
|
if (len == 0)
|
|
|
|
{
|
|
|
|
*outptr = (LPWSTR)empty;
|
|
|
|
*out = NULL;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!alloc_string(len, &str))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
priv = impl_from_HSTRING(str);
|
|
|
|
*outptr = priv->buffer;
|
2022-01-24 15:09:20 +00:00
|
|
|
*out = (HSTRING_BUFFER)&priv->buffer;
|
2014-12-15 08:24:50 +00:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WindowsDeleteStringBuffer (combase.@)
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI WindowsDeleteStringBuffer(HSTRING_BUFFER buf)
|
|
|
|
{
|
2022-01-24 15:09:20 +00:00
|
|
|
struct hstring_private *priv = NULL;
|
|
|
|
|
2015-10-25 14:32:15 +00:00
|
|
|
TRACE("(%p)\n", buf);
|
|
|
|
|
2022-01-24 15:09:20 +00:00
|
|
|
if(buf)
|
|
|
|
priv = impl_from_HSTRING_BUFFER(buf);
|
|
|
|
|
|
|
|
return WindowsDeleteString((HSTRING)priv);
|
2014-12-15 08:24:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WindowsPromoteStringBuffer (combase.@)
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI WindowsPromoteStringBuffer(HSTRING_BUFFER buf, HSTRING *out)
|
|
|
|
{
|
|
|
|
struct hstring_private *priv = impl_from_HSTRING_BUFFER(buf);
|
2015-10-25 14:32:15 +00:00
|
|
|
|
|
|
|
TRACE("(%p, %p)\n", buf, out);
|
|
|
|
|
2014-12-15 08:24:50 +00:00
|
|
|
if (out == NULL)
|
|
|
|
return E_POINTER;
|
|
|
|
if (buf == NULL)
|
|
|
|
{
|
|
|
|
*out = NULL;
|
|
|
|
return S_OK;
|
|
|
|
}
|
2022-01-24 15:09:21 +00:00
|
|
|
if (priv->buffer[priv->header.length] != 0 || priv->header.flags & HSTRING_REFERENCE_FLAG || priv->refcount != 1)
|
2014-12-15 08:24:50 +00:00
|
|
|
return E_INVALIDARG;
|
2022-01-24 15:09:20 +00:00
|
|
|
*out = (HSTRING)priv;
|
2014-12-15 08:24:50 +00:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2014-12-15 08:24:49 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* WindowsGetStringLen (combase.@)
|
|
|
|
*/
|
|
|
|
UINT32 WINAPI WindowsGetStringLen(HSTRING str)
|
|
|
|
{
|
|
|
|
struct hstring_private *priv = impl_from_HSTRING(str);
|
2015-10-25 14:32:15 +00:00
|
|
|
|
|
|
|
TRACE("(%p)\n", str);
|
|
|
|
|
2014-12-15 08:24:49 +00:00
|
|
|
if (str == NULL)
|
|
|
|
return 0;
|
2022-01-24 15:09:21 +00:00
|
|
|
return priv->header.length;
|
2014-12-15 08:24:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WindowsGetStringRawBuffer (combase.@)
|
|
|
|
*/
|
|
|
|
LPCWSTR WINAPI WindowsGetStringRawBuffer(HSTRING str, UINT32 *len)
|
|
|
|
{
|
|
|
|
struct hstring_private *priv = impl_from_HSTRING(str);
|
2015-10-25 14:32:15 +00:00
|
|
|
|
|
|
|
TRACE("(%p, %p)\n", str, len);
|
|
|
|
|
2014-12-15 08:24:49 +00:00
|
|
|
if (str == NULL)
|
|
|
|
{
|
|
|
|
if (len)
|
|
|
|
*len = 0;
|
|
|
|
return empty;
|
|
|
|
}
|
|
|
|
if (len)
|
2022-01-24 15:09:21 +00:00
|
|
|
*len = priv->header.length;
|
2022-01-24 15:09:22 +00:00
|
|
|
return priv->header.str;
|
2014-12-15 08:24:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WindowsStringHasEmbeddedNull (combase.@)
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI WindowsStringHasEmbeddedNull(HSTRING str, BOOL *out)
|
|
|
|
{
|
|
|
|
UINT32 i;
|
|
|
|
struct hstring_private *priv = impl_from_HSTRING(str);
|
2015-10-25 14:32:15 +00:00
|
|
|
|
|
|
|
TRACE("(%p, %p)\n", str, out);
|
|
|
|
|
2014-12-15 08:24:49 +00:00
|
|
|
if (out == NULL)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
if (str == NULL)
|
|
|
|
{
|
|
|
|
*out = FALSE;
|
|
|
|
return S_OK;
|
|
|
|
}
|
2022-01-24 15:09:21 +00:00
|
|
|
for (i = 0; i < priv->header.length; i++)
|
2014-12-15 08:24:49 +00:00
|
|
|
{
|
2022-01-24 15:09:22 +00:00
|
|
|
if (priv->header.str[i] == '\0')
|
2014-12-15 08:24:49 +00:00
|
|
|
{
|
|
|
|
*out = TRUE;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*out = FALSE;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2015-10-23 01:22:40 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* WindowsSubstring (combase.@)
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI WindowsSubstring(HSTRING str, UINT32 start, HSTRING *out)
|
|
|
|
{
|
|
|
|
struct hstring_private *priv = impl_from_HSTRING(str);
|
|
|
|
UINT32 len = WindowsGetStringLen(str);
|
2015-10-25 14:32:15 +00:00
|
|
|
|
|
|
|
TRACE("(%p, %u, %p)\n", str, start, out);
|
|
|
|
|
2015-10-23 01:22:40 +00:00
|
|
|
if (out == NULL)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
if (start > len)
|
|
|
|
return E_BOUNDS;
|
|
|
|
if (start == len)
|
|
|
|
{
|
|
|
|
*out = NULL;
|
|
|
|
return S_OK;
|
|
|
|
}
|
2022-01-24 15:09:22 +00:00
|
|
|
return WindowsCreateString(&priv->header.str[start], len - start, out);
|
2015-10-23 01:22:40 +00:00
|
|
|
}
|
|
|
|
|
2015-10-25 14:32:37 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* WindowsSubstringWithSpecifiedLength (combase.@)
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI WindowsSubstringWithSpecifiedLength(HSTRING str, UINT32 start, UINT32 len, HSTRING *out)
|
|
|
|
{
|
|
|
|
struct hstring_private *priv = impl_from_HSTRING(str);
|
|
|
|
|
|
|
|
TRACE("(%p, %u, %u, %p)\n", str, start, len, out);
|
|
|
|
|
|
|
|
if (out == NULL)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
if (start + len < start ||
|
|
|
|
start + len > WindowsGetStringLen(str))
|
|
|
|
return E_BOUNDS;
|
|
|
|
if (len == 0)
|
|
|
|
{
|
|
|
|
*out = NULL;
|
|
|
|
return S_OK;
|
|
|
|
}
|
2022-01-24 15:09:22 +00:00
|
|
|
return WindowsCreateString(&priv->header.str[start], len, out);
|
2015-10-25 14:32:37 +00:00
|
|
|
}
|
|
|
|
|
2015-10-29 04:07:17 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* WindowsConcatString (combase.@)
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI WindowsConcatString(HSTRING str1, HSTRING str2, HSTRING *out)
|
|
|
|
{
|
|
|
|
struct hstring_private *priv1 = impl_from_HSTRING(str1);
|
|
|
|
struct hstring_private *priv2 = impl_from_HSTRING(str2);
|
|
|
|
struct hstring_private *priv;
|
|
|
|
|
|
|
|
TRACE("(%p, %p, %p)\n", str1, str2, out);
|
|
|
|
|
|
|
|
if (out == NULL)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
if (str1 == NULL)
|
|
|
|
return WindowsDuplicateString(str2, out);
|
|
|
|
if (str2 == NULL)
|
|
|
|
return WindowsDuplicateString(str1, out);
|
2022-01-24 15:09:21 +00:00
|
|
|
if (!priv1->header.length && !priv2->header.length)
|
2015-10-29 04:07:17 +00:00
|
|
|
{
|
|
|
|
*out = NULL;
|
|
|
|
return S_OK;
|
|
|
|
}
|
2022-01-24 15:09:21 +00:00
|
|
|
if (!alloc_string(priv1->header.length + priv2->header.length, out))
|
2015-10-29 04:07:17 +00:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
priv = impl_from_HSTRING(*out);
|
2022-01-24 15:09:22 +00:00
|
|
|
memcpy(priv->buffer, priv1->header.str, priv1->header.length * sizeof(*priv1->buffer));
|
|
|
|
memcpy(priv->buffer + priv1->header.length, priv2->header.str, priv2->header.length * sizeof(*priv2->buffer));
|
2015-10-29 04:07:17 +00:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2014-12-15 08:24:49 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* WindowsIsStringEmpty (combase.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI WindowsIsStringEmpty(HSTRING str)
|
|
|
|
{
|
|
|
|
struct hstring_private *priv = impl_from_HSTRING(str);
|
2015-10-25 14:32:15 +00:00
|
|
|
|
|
|
|
TRACE("(%p)\n", str);
|
|
|
|
|
2014-12-15 08:24:49 +00:00
|
|
|
if (str == NULL)
|
|
|
|
return TRUE;
|
2022-01-24 15:09:21 +00:00
|
|
|
return priv->header.length == 0;
|
2014-12-15 08:24:49 +00:00
|
|
|
}
|
2016-02-10 22:25:23 +00:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WindowsCompareStringOrdinal (combase.@)
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI WindowsCompareStringOrdinal(HSTRING str1, HSTRING str2, INT32 *res)
|
|
|
|
{
|
|
|
|
struct hstring_private *priv1 = impl_from_HSTRING(str1);
|
|
|
|
struct hstring_private *priv2 = impl_from_HSTRING(str2);
|
|
|
|
const WCHAR *buf1 = empty, *buf2 = empty;
|
|
|
|
UINT32 len1 = 0, len2 = 0;
|
|
|
|
|
|
|
|
TRACE("(%p, %p, %p)\n", str1, str2, res);
|
|
|
|
|
|
|
|
if (res == NULL)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
if (str1 == str2)
|
|
|
|
{
|
|
|
|
*res = 0;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
if (str1)
|
|
|
|
{
|
2022-01-24 15:09:22 +00:00
|
|
|
buf1 = priv1->header.str;
|
2022-01-24 15:09:21 +00:00
|
|
|
len1 = priv1->header.length;
|
2016-02-10 22:25:23 +00:00
|
|
|
}
|
|
|
|
if (str2)
|
|
|
|
{
|
2022-01-24 15:09:22 +00:00
|
|
|
buf2 = priv2->header.str;
|
2022-01-24 15:09:21 +00:00
|
|
|
len2 = priv2->header.length;
|
2016-02-10 22:25:23 +00:00
|
|
|
}
|
|
|
|
*res = CompareStringOrdinal(buf1, len1, buf2, len2, FALSE) - CSTR_EQUAL;
|
|
|
|
return S_OK;
|
|
|
|
}
|
2016-02-10 22:27:15 +00:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WindowsTrimStringStart (combase.@)
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI WindowsTrimStringStart(HSTRING str1, HSTRING str2, HSTRING *out)
|
|
|
|
{
|
|
|
|
struct hstring_private *priv1 = impl_from_HSTRING(str1);
|
|
|
|
struct hstring_private *priv2 = impl_from_HSTRING(str2);
|
|
|
|
UINT32 start;
|
|
|
|
|
|
|
|
TRACE("(%p, %p, %p)\n", str1, str2, out);
|
|
|
|
|
2022-01-24 15:09:21 +00:00
|
|
|
if (!out || !str2 || !priv2->header.length)
|
2016-02-10 22:27:15 +00:00
|
|
|
return E_INVALIDARG;
|
|
|
|
if (!str1)
|
|
|
|
{
|
|
|
|
*out = NULL;
|
|
|
|
return S_OK;
|
|
|
|
}
|
2022-01-24 15:09:21 +00:00
|
|
|
for (start = 0; start < priv1->header.length; start++)
|
2016-02-10 22:27:15 +00:00
|
|
|
{
|
2022-01-24 15:09:22 +00:00
|
|
|
if (!wmemchr(priv2->header.str, priv1->header.str[start], priv2->header.length))
|
2016-02-10 22:27:15 +00:00
|
|
|
break;
|
|
|
|
}
|
2022-01-24 15:09:22 +00:00
|
|
|
return start ? WindowsCreateString(&priv1->header.str[start], priv1->header.length - start, out) :
|
2016-02-10 22:27:15 +00:00
|
|
|
WindowsDuplicateString(str1, out);
|
|
|
|
}
|
2016-02-10 22:27:40 +00:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WindowsTrimStringEnd (combase.@)
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI WindowsTrimStringEnd(HSTRING str1, HSTRING str2, HSTRING *out)
|
|
|
|
{
|
|
|
|
struct hstring_private *priv1 = impl_from_HSTRING(str1);
|
|
|
|
struct hstring_private *priv2 = impl_from_HSTRING(str2);
|
|
|
|
UINT32 len;
|
|
|
|
|
|
|
|
TRACE("(%p, %p, %p)\n", str1, str2, out);
|
|
|
|
|
2022-01-24 15:09:21 +00:00
|
|
|
if (!out || !str2 || !priv2->header.length)
|
2016-02-10 22:27:40 +00:00
|
|
|
return E_INVALIDARG;
|
|
|
|
if (!str1)
|
|
|
|
{
|
|
|
|
*out = NULL;
|
|
|
|
return S_OK;
|
|
|
|
}
|
2022-01-24 15:09:21 +00:00
|
|
|
for (len = priv1->header.length; len > 0; len--)
|
2016-02-10 22:27:40 +00:00
|
|
|
{
|
2022-01-24 15:09:22 +00:00
|
|
|
if (!wmemchr(priv2->header.str, priv1->header.str[len - 1], priv2->header.length))
|
2016-02-10 22:27:40 +00:00
|
|
|
break;
|
|
|
|
}
|
2022-01-24 15:09:22 +00:00
|
|
|
return (len < priv1->header.length) ? WindowsCreateString(priv1->header.str, len, out) :
|
2016-02-10 22:27:40 +00:00
|
|
|
WindowsDuplicateString(str1, out);
|
|
|
|
}
|