wininet: Support the Cache-Control max-age directive for setting url cache entry...
[wine/testsucceed.git] / dlls / infosoft / wordbreaker.c
blob69e2eb886621e93a531554f158ec7a7f6ce2f054
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
23 #include "config.h"
25 #include <stdarg.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winuser.h"
30 #include "ole2.h"
31 #include "indexsrv.h"
32 #include "wine/unicode.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(infosoft);
37 typedef struct tag_wordbreaker_impl
39 IWordBreaker IWordBreaker_iface;
40 LONG ref;
41 } wordbreaker_impl;
43 static inline wordbreaker_impl *impl_from_IWordBreaker(IWordBreaker *iface)
45 return CONTAINING_RECORD(iface, wordbreaker_impl, IWordBreaker_iface);
48 static HRESULT WINAPI wb_QueryInterface( IWordBreaker *iface,
49 REFIID riid, LPVOID *ppvObj)
51 wordbreaker_impl *This = impl_from_IWordBreaker(iface);
53 TRACE("(%p)->(%s)\n",This,debugstr_guid(riid));
55 *ppvObj = NULL;
57 if (IsEqualIID(riid, &IID_IUnknown) ||
58 IsEqualIID(riid, &IID_IWordBreaker))
60 *ppvObj = This;
61 return S_OK;
64 TRACE("-- E_NOINTERFACE\n");
65 return E_NOINTERFACE;
68 static ULONG WINAPI wb_AddRef( IWordBreaker *iface )
70 wordbreaker_impl *This = impl_from_IWordBreaker(iface);
71 return InterlockedIncrement(&This->ref);
74 static ULONG WINAPI wb_Release(IWordBreaker *iface)
76 wordbreaker_impl *This = impl_from_IWordBreaker(iface);
77 LONG refcount;
79 refcount = InterlockedDecrement(&This->ref);
80 if (!refcount)
81 HeapFree(GetProcessHeap(), 0, This);
83 return refcount;
86 static HRESULT WINAPI wb_Init( IWordBreaker *iface,
87 BOOL fQuery, ULONG ulMaxTokenSize, BOOL *pfLicense )
89 TRACE("%d %u\n", fQuery, ulMaxTokenSize);
90 *pfLicense = FALSE;
91 return S_OK;
94 static HRESULT call_sink( IWordSink *pWordSink, TEXT_SOURCE *ts, UINT len )
96 HRESULT r;
98 if (!len)
99 return S_OK;
101 TRACE("%d %s\n", len, debugstr_w(&ts->awcBuffer[ts->iCur]));
103 r = IWordSink_PutWord( pWordSink, len, &ts->awcBuffer[ts->iCur], len, ts->iCur );
104 ts->iCur += len;
106 return r;
109 static HRESULT WINAPI wb_BreakText( IWordBreaker *iface,
110 TEXT_SOURCE *ts, IWordSink *pWordSink, IPhraseSink *pPhraseSink)
112 UINT len, state = 0;
113 WCHAR ch;
115 TRACE("%p %p %p\n", ts, pWordSink, pPhraseSink);
117 if (pPhraseSink)
118 FIXME("IPhraseSink won't be called\n");
122 len = 0;
123 while ((ts->iCur + len) < ts->iEnd)
125 ch = ts->awcBuffer[ts->iCur + len];
127 switch (state)
129 case 0: /* skip spaces and punctuation */
131 if (!ch || ispunctW(ch) || isspaceW(ch))
132 ts->iCur ++;
133 else
134 state = 1;
135 break;
137 case 1: /* find the end of the word */
139 if (ch && !ispunctW(ch) && !isspaceW(ch))
140 len++;
141 else
143 call_sink( pWordSink, ts, len );
144 len = 0;
145 state = 0;
147 break;
151 call_sink( pWordSink, ts, len );
153 } while (S_OK == ts->pfnFillTextBuffer( ts ));
155 return S_OK;
158 static HRESULT WINAPI wb_ComposePhrase( IWordBreaker *iface,
159 const WCHAR *pwcNoun, ULONG cwcNoun,
160 const WCHAR *pwcModifier, ULONG cwcModifier,
161 ULONG ulAttachmentType, WCHAR *pwcPhrase, ULONG *pcwcPhrase)
163 FIXME("%p %u %p %u %u %p %p\n", pwcNoun, cwcNoun,
164 pwcModifier, cwcModifier, ulAttachmentType, pwcPhrase, pcwcPhrase);
165 return S_OK;
168 static HRESULT WINAPI wb_GetLicenseToUse( IWordBreaker *iface, const WCHAR **ppwcsLicense )
170 FIXME("%p\n", ppwcsLicense);
171 *ppwcsLicense = NULL;
172 return S_OK;
175 static const IWordBreakerVtbl wordbreaker_vtbl =
177 wb_QueryInterface,
178 wb_AddRef,
179 wb_Release,
180 wb_Init,
181 wb_BreakText,
182 wb_ComposePhrase,
183 wb_GetLicenseToUse,
186 HRESULT WINAPI wb_Constructor(IUnknown* pUnkOuter, REFIID riid, LPVOID *ppvObject)
188 wordbreaker_impl *This;
189 IWordBreaker *wb;
191 TRACE("%p %s %p\n", pUnkOuter, debugstr_guid(riid), ppvObject);
193 This = HeapAlloc(GetProcessHeap(), 0, sizeof *This);
194 if (!This)
195 return E_OUTOFMEMORY;
197 This->ref = 1;
198 This->IWordBreaker_iface.lpVtbl = &wordbreaker_vtbl;
200 wb = &This->IWordBreaker_iface;
202 return IWordBreaker_QueryInterface(wb, riid, ppvObject);