check beginning of file for book title, author and series
| 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 ); |
no test coverage detected