| 573 | } |
| 574 | |
| 575 | void BookParser_t::createBook(std::string filename) |
| 576 | { |
| 577 | //Load in the text from a file. |
| 578 | std::string tempstr = "books/"; |
| 579 | tempstr.append(filename); |
| 580 | if ( PHYSFS_getRealDir(tempstr.c_str()) != nullptr ) |
| 581 | { |
| 582 | std::string path = PHYSFS_getRealDir(tempstr.c_str()); |
| 583 | path.append(PHYSFS_getDirSeparator()); |
| 584 | tempstr = path + tempstr; |
| 585 | } |
| 586 | |
| 587 | allBooks.push_back(Book_t()); |
| 588 | auto& newBook = allBooks[allBooks.size() - 1]; |
| 589 | |
| 590 | char bookChar[PATH_MAX]; |
| 591 | strncpy(bookChar, tempstr.c_str(), PATH_MAX - 1); |
| 592 | char* tmp = readFile(bookChar); |
| 593 | if ( tmp ) |
| 594 | { |
| 595 | newBook.text = tmp; |
| 596 | } |
| 597 | free(tmp); |
| 598 | if ( newBook.text == "" ) |
| 599 | { |
| 600 | printlog( "error opening book \"%s\".\n", tempstr.c_str()); |
| 601 | return; //Failed to open the file. |
| 602 | } |
| 603 | |
| 604 | newBook.default_name = filename; |
| 605 | auto findTxt = newBook.default_name.find(".txt"); |
| 606 | if ( findTxt != std::string::npos ) |
| 607 | { |
| 608 | newBook.default_name = newBook.default_name.substr(0, findTxt); |
| 609 | } |
| 610 | //newBook.rawBookText = book->text; |
| 611 | |
| 612 | std::string pageText = ""; |
| 613 | for ( auto& character : newBook.text ) |
| 614 | { |
| 615 | if ( character == '\r' ) |
| 616 | { |
| 617 | continue; |
| 618 | } |
| 619 | if ( character == '\t' ) |
| 620 | { |
| 621 | for ( int insertTabs = 3; insertTabs > 0; --insertTabs ) |
| 622 | { |
| 623 | pageText += ' '; |
| 624 | } |
| 625 | } |
| 626 | else |
| 627 | { |
| 628 | pageText += character; |
| 629 | } |
| 630 | } |
| 631 | |
| 632 | const int MAX_PARSE_CHARACTERS = 65535; |
nothing calls this directly
no test coverage detected