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
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
;
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
));
57 if (IsEqualIID(riid
, &IID_IUnknown
) ||
58 IsEqualIID(riid
, &IID_IWordBreaker
))
64 TRACE("-- E_NOINTERFACE\n");
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
);
79 refcount
= InterlockedDecrement(&This
->ref
);
81 HeapFree(GetProcessHeap(), 0, This
);
86 static HRESULT WINAPI
wb_Init( IWordBreaker
*iface
,
87 BOOL fQuery
, ULONG ulMaxTokenSize
, BOOL
*pfLicense
)
89 TRACE("%d %u\n", fQuery
, ulMaxTokenSize
);
94 static HRESULT
call_sink( IWordSink
*pWordSink
, TEXT_SOURCE
*ts
, UINT len
)
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
);
109 static HRESULT WINAPI
wb_BreakText( IWordBreaker
*iface
,
110 TEXT_SOURCE
*ts
, IWordSink
*pWordSink
, IPhraseSink
*pPhraseSink
)
115 TRACE("%p %p %p\n", ts
, pWordSink
, pPhraseSink
);
118 FIXME("IPhraseSink won't be called\n");
123 while ((ts
->iCur
+ len
) < ts
->iEnd
)
125 ch
= ts
->awcBuffer
[ts
->iCur
+ len
];
129 case 0: /* skip spaces and punctuation */
131 if (!ch
|| ispunctW(ch
) || isspaceW(ch
))
137 case 1: /* find the end of the word */
139 if (ch
&& !ispunctW(ch
) && !isspaceW(ch
))
143 call_sink( pWordSink
, ts
, len
);
151 call_sink( pWordSink
, ts
, len
);
153 } while (S_OK
== ts
->pfnFillTextBuffer( ts
));
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
);
168 static HRESULT WINAPI
wb_GetLicenseToUse( IWordBreaker
*iface
, const WCHAR
**ppwcsLicense
)
170 FIXME("%p\n", ppwcsLicense
);
171 *ppwcsLicense
= NULL
;
175 static const IWordBreakerVtbl wordbreaker_vtbl
=
186 DECLSPEC_HIDDEN HRESULT WINAPI
wb_Constructor(IUnknown
* pUnkOuter
, REFIID riid
, LPVOID
*ppvObject
)
188 wordbreaker_impl
*This
;
191 TRACE("%p %s %p\n", pUnkOuter
, debugstr_guid(riid
), ppvObject
);
193 This
= HeapAlloc(GetProcessHeap(), 0, sizeof *This
);
195 return E_OUTOFMEMORY
;
198 This
->IWordBreaker_iface
.lpVtbl
= &wordbreaker_vtbl
;
200 wb
= &This
->IWordBreaker_iface
;
202 return IWordBreaker_QueryInterface(wb
, riid
, ppvObject
);