Skip to content

Commit ea0da98

Browse files
committed
sentenceinfo: implement exportSentenceInfo(infile, outfile) in lvdocview
1 parent 5b34f07 commit ea0da98

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

crengine/include/lvdocview.h

+3
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,9 @@ class LVDocView : public CacheLoadingCallback
955955
/// load document from stream
956956
bool LoadDocument( LVStreamRef stream, const lChar32 * contentPath, bool metadataOnly = false );
957957

958+
/// load document and export sentence info
959+
bool exportSentenceInfo(const lChar32 * inputFileName, const lChar32 * outputFileName);
960+
958961
/// save last file position
959962
void savePosition();
960963
/// restore last file position

crengine/src/lvdocview.cpp

+35
Original file line numberDiff line numberDiff line change
@@ -4043,6 +4043,41 @@ static bool needToConvertBookmarks(CRFileHistRecord* historyRecord, lUInt32 domV
40434043
return convertBookmarks;
40444044
}
40454045

4046+
bool LVDocView::exportSentenceInfo(const lChar32 * inputFileName, const lChar32 * outputFileName) {
4047+
if (!LoadDocument(inputFileName, false)) {
4048+
return false;
4049+
}
4050+
4051+
LVStreamRef out = LVOpenFileStream(outputFileName, LVOM_WRITE);
4052+
if ( out.isNull() ) {
4053+
return false;
4054+
}
4055+
4056+
checkRender();
4057+
4058+
ldomXPointerEx ptrStart( m_doc->getRootNode(), m_doc->getRootNode()->getChildCount());
4059+
if ( !ptrStart.thisSentenceStart() ) {
4060+
ptrStart.nextSentenceStart();
4061+
}
4062+
4063+
if ( !ptrStart.thisSentenceStart() ) {
4064+
return false;
4065+
}
4066+
4067+
while ( 1 ) {
4068+
ldomXPointerEx ptrEnd(ptrStart);
4069+
ptrEnd.thisSentenceEnd();
4070+
4071+
ldomXRange range(ptrStart, ptrEnd);
4072+
lString32 sentenceText = range.getRangeText();
4073+
*out << UnicodeToUtf8(ptrStart.toString()) << "," << UnicodeToUtf8(sentenceText) << "\n";
4074+
if ( !ptrStart.nextSentenceStart() ) {
4075+
break;
4076+
}
4077+
}
4078+
return true;
4079+
}
4080+
40464081
/// load document from file
40474082
bool LVDocView::LoadDocument(const lChar32 * fname, bool metadataOnly) {
40484083
if (!fname || !fname[0])

0 commit comments

Comments
 (0)