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
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(infosoft
);
35 typedef struct tag_wordbreaker_impl
37 IWordBreaker IWordBreaker_iface
;
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
));
55 if (IsEqualIID(riid
, &IID_IUnknown
) ||
56 IsEqualIID(riid
, &IID_IWordBreaker
))
58 *ppvObj
= &This
->IWordBreaker_iface
;
62 TRACE("-- E_NOINTERFACE\n");
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
);
77 refcount
= InterlockedDecrement(&This
->ref
);
79 HeapFree(GetProcessHeap(), 0, This
);
84 static HRESULT WINAPI
wb_Init( IWordBreaker
*iface
,
85 BOOL fQuery
, ULONG ulMaxTokenSize
, BOOL
*pfLicense
)
87 TRACE("%d %u\n", fQuery
, ulMaxTokenSize
);
92 static HRESULT
call_sink( IWordSink
*pWordSink
, TEXT_SOURCE
*ts
, UINT len
)
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
);
107 static HRESULT WINAPI
wb_BreakText( IWordBreaker
*iface
,
108 TEXT_SOURCE
*ts
, IWordSink
*pWordSink
, IPhraseSink
*pPhraseSink
)
113 TRACE("%p %p %p\n", ts
, pWordSink
, pPhraseSink
);
116 FIXME("IPhraseSink won't be called\n");
121 while ((ts
->iCur
+ len
) < ts
->iEnd
)
123 ch
= ts
->awcBuffer
[ts
->iCur
+ len
];
127 case 0: /* skip spaces and punctuation */
129 if (!ch
|| iswpunct(ch
) || iswspace(ch
))
135 case 1: /* find the end of the word */
137 if (ch
&& !iswpunct(ch
) && !iswspace(ch
))
141 call_sink( pWordSink
, ts
, len
);
149 call_sink( pWordSink
, ts
, len
);
151 } while (S_OK
== ts
->pfnFillTextBuffer( ts
));
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
);
166 static HRESULT WINAPI
wb_GetLicenseToUse( IWordBreaker
*iface
, const WCHAR
**ppwcsLicense
)
168 FIXME("%p\n", ppwcsLicense
);
169 *ppwcsLicense
= NULL
;
173 static const IWordBreakerVtbl wordbreaker_vtbl
=
184 DECLSPEC_HIDDEN HRESULT WINAPI
wb_Constructor(IUnknown
* pUnkOuter
, REFIID riid
, LPVOID
*ppvObject
)
186 wordbreaker_impl
*This
;
189 TRACE("%p %s %p\n", pUnkOuter
, debugstr_guid(riid
), ppvObject
);
191 This
= HeapAlloc(GetProcessHeap(), 0, sizeof *This
);
193 return E_OUTOFMEMORY
;
196 This
->IWordBreaker_iface
.lpVtbl
= &wordbreaker_vtbl
;
198 wb
= &This
->IWordBreaker_iface
;
200 return IWordBreaker_QueryInterface(wb
, riid
, ppvObject
);