MCPcopy Create free account
hub / github.com/buggins/coolreader / DetectBookDescription

Method DetectBookDescription

crengine/src/lvxml.cpp:1586–1669  ·  view source on GitHub ↗

check beginning of file for book title, author and series

Source from the content-addressed store, hash-verified

1584
1585 /// check beginning of file for book title, author and series
1586 bool DetectBookDescription(LVXMLParserCallback * callback)
1587 {
1588
1589 if ( !testProjectGutenbergHeader() && !testAuthorDotTitleFormat() ) {
1590 bookTitle = LVExtractFilenameWithoutExtension( file->getFileName() );
1591 bookAuthors.clear();
1592/*
1593
1594 int necount = 0;
1595 lString16 s[3];
1596 unsigned i;
1597 for ( i=0; i<(unsigned)length() && necount<2; i++ ) {
1598 LVTextFileLine * item = get(i);
1599 if ( item->rpos>item->lpos ) {
1600 lString16 str = item->text;
1601 str.trimDoubleSpaces(false, false, true);
1602 if ( !str.empty() ) {
1603 s[necount] = str;
1604 necount++;
1605 }
1606 }
1607 }
1608 //update book description
1609 if ( i==0 ) {
1610 bookTitle = L"no name";
1611 } else {
1612 bookTitle = s[1];
1613 }
1614 bookAuthors = s[0];
1615*/
1616 }
1617
1618 lString16Collection author_list;
1619 if ( !bookAuthors.empty() )
1620 author_list.parse( bookAuthors, ',', true );
1621
1622 unsigned i;
1623 for ( i=0; i<author_list.length(); i++ ) {
1624 lString16Collection name_list;
1625 name_list.parse( author_list[i], ' ', true );
1626 if ( name_list.length()>0 ) {
1627 lString16 firstName = name_list[0];
1628 lString16 lastName;
1629 lString16 middleName;
1630 if ( name_list.length() == 2 ) {
1631 lastName = name_list[1];
1632 } else if ( name_list.length()>2 ) {
1633 middleName = name_list[1];
1634 lastName = name_list[2];
1635 }
1636 callback->OnTagOpenNoAttr( NULL, L"author" );
1637 callback->OnTagOpenNoAttr( NULL, L"first-name" );
1638 if ( !firstName.empty() )
1639 callback->OnText( firstName.c_str(), firstName.length(), TXTFLG_TRIM|TXTFLG_TRIM_REMOVE_EOL_HYPHENS );
1640 callback->OnTagClose( NULL, L"first-name" );
1641 callback->OnTagOpenNoAttr( NULL, L"middle-name" );
1642 if ( !middleName.empty() )
1643 callback->OnText( middleName.c_str(), middleName.length(), TXTFLG_TRIM|TXTFLG_TRIM_REMOVE_EOL_HYPHENS );

Callers 1

ParseMethod · 0.80

Calls 11

OnTagOpenNoAttrMethod · 0.80
getFileNameMethod · 0.45
clearMethod · 0.45
emptyMethod · 0.45
parseMethod · 0.45
lengthMethod · 0.45
OnTextMethod · 0.45
c_strMethod · 0.45
OnTagCloseMethod · 0.45
OnAttributeMethod · 0.45

Tested by

no test coverage detected