2006-07-11 04:13:18 +02:00
|
|
|
/*
|
|
|
|
* Word splitter Implementation
|
|
|
|
*
|
|
|
|
* Copyright 2006 Mike McCormack
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
#include "ole2.h"
|
2006-08-11 13:21:46 +02:00
|
|
|
#include "indexsrv.h"
|
2006-07-11 04:13:18 +02:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(infosoft);
|
|
|
|
|
|
|
|
typedef struct tag_wordbreaker_impl
|
|
|
|
{
|
2010-12-08 22:59:32 +01:00
|
|
|
IWordBreaker IWordBreaker_iface;
|
2006-07-11 04:13:18 +02:00
|
|
|
LONG ref;
|
|
|
|
} wordbreaker_impl;
|
|
|
|
|
2010-12-08 22:59:32 +01:00
|
|
|
static inline wordbreaker_impl *impl_from_IWordBreaker(IWordBreaker *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, wordbreaker_impl, IWordBreaker_iface);
|
|
|
|
}
|
|
|
|
|
2006-07-11 04:13:18 +02:00
|
|
|
static HRESULT WINAPI wb_QueryInterface( IWordBreaker *iface,
|
|
|
|
REFIID riid, LPVOID *ppvObj)
|
|
|
|
{
|
2010-12-08 22:59:32 +01:00
|
|
|
wordbreaker_impl *This = impl_from_IWordBreaker(iface);
|
2006-07-11 04:13:18 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%s)\n",This,debugstr_guid(riid));
|
|
|
|
|
|
|
|
*ppvObj = NULL;
|
|
|
|
|
|
|
|
if (IsEqualIID(riid, &IID_IUnknown) ||
|
|
|
|
IsEqualIID(riid, &IID_IWordBreaker))
|
|
|
|
{
|
2017-02-13 12:16:04 +01:00
|
|
|
*ppvObj = &This->IWordBreaker_iface;
|
2006-07-11 04:13:18 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("-- E_NOINTERFACE\n");
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI wb_AddRef( IWordBreaker *iface )
|
|
|
|
{
|
2010-12-08 22:59:32 +01:00
|
|
|
wordbreaker_impl *This = impl_from_IWordBreaker(iface);
|
2006-07-11 04:13:18 +02:00
|
|
|
return InterlockedIncrement(&This->ref);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI wb_Release(IWordBreaker *iface)
|
|
|
|
{
|
2010-12-08 22:59:32 +01:00
|
|
|
wordbreaker_impl *This = impl_from_IWordBreaker(iface);
|
2006-07-11 04:13:18 +02:00
|
|
|
LONG refcount;
|
|
|
|
|
|
|
|
refcount = InterlockedDecrement(&This->ref);
|
|
|
|
if (!refcount)
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI wb_Init( IWordBreaker *iface,
|
|
|
|
BOOL fQuery, ULONG ulMaxTokenSize, BOOL *pfLicense )
|
|
|
|
{
|
2006-10-04 11:50:42 +02:00
|
|
|
TRACE("%d %u\n", fQuery, ulMaxTokenSize);
|
2006-07-11 04:13:18 +02:00
|
|
|
*pfLicense = FALSE;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2006-08-11 13:08:25 +02:00
|
|
|
static HRESULT call_sink( IWordSink *pWordSink, TEXT_SOURCE *ts, UINT len )
|
2006-07-11 04:13:18 +02:00
|
|
|
{
|
2006-08-11 13:08:25 +02:00
|
|
|
HRESULT r;
|
2006-07-11 04:13:18 +02:00
|
|
|
|
2006-08-11 13:08:25 +02:00
|
|
|
if (!len)
|
|
|
|
return S_OK;
|
2006-07-11 04:13:18 +02:00
|
|
|
|
2006-08-11 13:08:25 +02:00
|
|
|
TRACE("%d %s\n", len, debugstr_w(&ts->awcBuffer[ts->iCur]));
|
2006-07-11 04:13:18 +02:00
|
|
|
|
2006-08-11 13:08:25 +02:00
|
|
|
r = IWordSink_PutWord( pWordSink, len, &ts->awcBuffer[ts->iCur], len, ts->iCur );
|
|
|
|
ts->iCur += len;
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
2006-07-11 04:13:18 +02:00
|
|
|
|
2006-08-11 13:08:25 +02:00
|
|
|
static HRESULT WINAPI wb_BreakText( IWordBreaker *iface,
|
|
|
|
TEXT_SOURCE *ts, IWordSink *pWordSink, IPhraseSink *pPhraseSink)
|
|
|
|
{
|
|
|
|
UINT len, state = 0;
|
|
|
|
WCHAR ch;
|
2006-07-11 04:13:18 +02:00
|
|
|
|
2006-08-11 13:08:25 +02:00
|
|
|
TRACE("%p %p %p\n", ts, pWordSink, pPhraseSink);
|
2006-07-11 04:13:18 +02:00
|
|
|
|
2006-08-11 13:08:25 +02:00
|
|
|
if (pPhraseSink)
|
|
|
|
FIXME("IPhraseSink won't be called\n");
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
len = 0;
|
|
|
|
while ((ts->iCur + len) < ts->iEnd)
|
|
|
|
{
|
|
|
|
ch = ts->awcBuffer[ts->iCur + len];
|
|
|
|
|
|
|
|
switch (state)
|
|
|
|
{
|
|
|
|
case 0: /* skip spaces and punctuation */
|
|
|
|
|
2019-06-06 09:02:08 +02:00
|
|
|
if (!ch || iswpunct(ch) || iswspace(ch))
|
2006-08-11 13:08:25 +02:00
|
|
|
ts->iCur ++;
|
|
|
|
else
|
|
|
|
state = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1: /* find the end of the word */
|
|
|
|
|
2019-06-06 09:02:08 +02:00
|
|
|
if (ch && !iswpunct(ch) && !iswspace(ch))
|
2006-08-11 13:08:25 +02:00
|
|
|
len++;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
call_sink( pWordSink, ts, len );
|
|
|
|
len = 0;
|
|
|
|
state = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
call_sink( pWordSink, ts, len );
|
|
|
|
|
|
|
|
} while (S_OK == ts->pfnFillTextBuffer( ts ));
|
2006-07-11 04:13:18 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI wb_ComposePhrase( IWordBreaker *iface,
|
|
|
|
const WCHAR *pwcNoun, ULONG cwcNoun,
|
|
|
|
const WCHAR *pwcModifier, ULONG cwcModifier,
|
|
|
|
ULONG ulAttachmentType, WCHAR *pwcPhrase, ULONG *pcwcPhrase)
|
|
|
|
{
|
2006-10-04 11:50:42 +02:00
|
|
|
FIXME("%p %u %p %u %u %p %p\n", pwcNoun, cwcNoun,
|
2006-07-11 04:13:18 +02:00
|
|
|
pwcModifier, cwcModifier, ulAttachmentType, pwcPhrase, pcwcPhrase);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI wb_GetLicenseToUse( IWordBreaker *iface, const WCHAR **ppwcsLicense )
|
|
|
|
{
|
|
|
|
FIXME("%p\n", ppwcsLicense);
|
|
|
|
*ppwcsLicense = NULL;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IWordBreakerVtbl wordbreaker_vtbl =
|
|
|
|
{
|
|
|
|
wb_QueryInterface,
|
|
|
|
wb_AddRef,
|
|
|
|
wb_Release,
|
|
|
|
wb_Init,
|
|
|
|
wb_BreakText,
|
|
|
|
wb_ComposePhrase,
|
|
|
|
wb_GetLicenseToUse,
|
|
|
|
};
|
|
|
|
|
2011-05-13 17:16:53 +02:00
|
|
|
DECLSPEC_HIDDEN HRESULT WINAPI wb_Constructor(IUnknown* pUnkOuter, REFIID riid, LPVOID *ppvObject)
|
2006-07-11 04:13:18 +02:00
|
|
|
{
|
|
|
|
wordbreaker_impl *This;
|
|
|
|
IWordBreaker *wb;
|
|
|
|
|
2006-08-11 13:08:25 +02:00
|
|
|
TRACE("%p %s %p\n", pUnkOuter, debugstr_guid(riid), ppvObject);
|
2006-07-11 04:13:18 +02:00
|
|
|
|
|
|
|
This = HeapAlloc(GetProcessHeap(), 0, sizeof *This);
|
|
|
|
if (!This)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
This->ref = 1;
|
2010-12-08 22:59:32 +01:00
|
|
|
This->IWordBreaker_iface.lpVtbl = &wordbreaker_vtbl;
|
2006-07-11 04:13:18 +02:00
|
|
|
|
2010-12-08 22:59:32 +01:00
|
|
|
wb = &This->IWordBreaker_iface;
|
2006-07-11 04:13:18 +02:00
|
|
|
|
|
|
|
return IWordBreaker_QueryInterface(wb, riid, ppvObject);
|
|
|
|
}
|