hidclass.sys: Support parsing of explicit usage page.
[wine.git] / dlls / infosoft / wordbreaker.c
blobaa432eb6bc4d5672b0a34dee88fa2a9ba48f56a6
1 /*
2 * Word splitter Implementation
4 * Copyright 2006 Mike McCormack
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define COBJMACROS
24 #include <stdarg.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "ole2.h"
30 #include "indexsrv.h"
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(infosoft);
35 typedef struct tag_wordbreaker_impl
37 IWordBreaker IWordBreaker_iface;
38 LONG ref;
39 } wordbreaker_impl;
41 static inline wordbreaker_impl *impl_from_IWordBreaker(IWordBreaker *iface)
43 return CONTAINING_RECORD(iface, wordbreaker_impl, IWordBreaker_iface);
46 static HRESULT WINAPI wb_QueryInterface( IWordBreaker *iface,
47 REFIID riid, LPVOID *ppvObj)
49 wordbreaker_impl *This = impl_from_IWordBreaker(iface);
51 TRACE("(%p)->(%s)\n",This,debugstr_guid(riid));
53 *ppvObj = NULL;
55 if (IsEqualIID(riid, &IID_IUnknown) ||
56 IsEqualIID(riid, &IID_IWordBreaker))
58 *ppvObj = &This->IWordBreaker_iface;
59 return S_OK;
62 TRACE("-- E_NOINTERFACE\n");
63 return E_NOINTERFACE;
66 static ULONG WINAPI wb_AddRef( IWordBreaker *iface )
68 wordbreaker_impl *This = impl_from_IWordBreaker(iface);
69 return InterlockedIncrement(&This->ref);
72 static ULONG WINAPI wb_Release(IWordBreaker *iface)
74 wordbreaker_impl *This = impl_from_IWordBreaker(iface);
75 LONG refcount;
77 refcount = InterlockedDecrement(&This->ref);
78 if (!refcount)
79 HeapFree(GetProcessHeap(), 0, This);
81 return refcount;
84 static HRESULT WINAPI wb_Init( IWordBreaker *iface,
85 BOOL fQuery, ULONG ulMaxTokenSize, BOOL *pfLicense )
87 TRACE("%d %u\n", fQuery, ulMaxTokenSize);
88 *pfLicense = FALSE;
89 return S_OK;
92 static HRESULT call_sink( IWordSink *pWordSink, TEXT_SOURCE *ts, UINT len )
94 HRESULT r;
96 if (!len)
97 return S_OK;
99 TRACE("%d %s\n", len, debugstr_w(&ts->awcBuffer[ts->iCur]));
101 r = IWordSink_PutWord( pWordSink, len, &ts->awcBuffer[ts->iCur], len, ts->iCur );
102 ts->iCur += len;
104 return r;
107 static HRESULT WINAPI wb_BreakText( IWordBreaker *iface,
108 TEXT_SOURCE *ts, IWordSink *pWordSink, IPhraseSink *pPhraseSink)
110 UINT len, state = 0;
111 WCHAR ch;
113 TRACE("%p %p %p\n", ts, pWordSink, pPhraseSink);
115 if (pPhraseSink)
116 FIXME("IPhraseSink won't be called\n");
120 len = 0;
121 while ((ts->iCur + len) < ts->iEnd)
123 ch = ts->awcBuffer[ts->iCur + len];
125 switch (state)
127 case 0: /* skip spaces and punctuation */
129 if (!ch || iswpunct(ch) || iswspace(ch))
130 ts->iCur ++;
131 else
132 state = 1;
133 break;
135 case 1: /* find the end of the word */
137 if (ch && !iswpunct(ch) && !iswspace(ch))
138 len++;
139 else
141 call_sink( pWordSink, ts, len );
142 len = 0;
143 state = 0;
145 break;
149 call_sink( pWordSink, ts, len );
151 } while (S_OK == ts->pfnFillTextBuffer( ts ));
153 return S_OK;
156 static HRESULT WINAPI wb_ComposePhrase( IWordBreaker *iface,
157 const WCHAR *pwcNoun, ULONG cwcNoun,
158 const WCHAR *pwcModifier, ULONG cwcModifier,
159 ULONG ulAttachmentType, WCHAR *pwcPhrase, ULONG *pcwcPhrase)
161 FIXME("%p %u %p %u %u %p %p\n", pwcNoun, cwcNoun,
162 pwcModifier, cwcModifier, ulAttachmentType, pwcPhrase, pcwcPhrase);
163 return S_OK;
166 static HRESULT WINAPI wb_GetLicenseToUse( IWordBreaker *iface, const WCHAR **ppwcsLicense )
168 FIXME("%p\n", ppwcsLicense);
169 *ppwcsLicense = NULL;
170 return S_OK;
173 static const IWordBreakerVtbl wordbreaker_vtbl =
175 wb_QueryInterface,
176 wb_AddRef,
177 wb_Release,
178 wb_Init,
179 wb_BreakText,
180 wb_ComposePhrase,
181 wb_GetLicenseToUse,
184 DECLSPEC_HIDDEN HRESULT WINAPI wb_Constructor(IUnknown* pUnkOuter, REFIID riid, LPVOID *ppvObject)
186 wordbreaker_impl *This;
187 IWordBreaker *wb;
189 TRACE("%p %s %p\n", pUnkOuter, debugstr_guid(riid), ppvObject);
191 This = HeapAlloc(GetProcessHeap(), 0, sizeof *This);
192 if (!This)
193 return E_OUTOFMEMORY;
195 This->ref = 1;
196 This->IWordBreaker_iface.lpVtbl = &wordbreaker_vtbl;
198 wb = &This->IWordBreaker_iface;
200 return IWordBreaker_QueryInterface(wb, riid, ppvObject);