2
* FBReader -- electronic book reader
3
* Copyright (C) 2004-2007 Nikolay Pultsin <geometer@mawhrin.net>
4
* Copyright (C) 2005 Mikhail Sobolev <mss@mawhrin.net>
2
* Copyright (C) 2004-2008 Geometer Plus <contact@geometerplus.com>
6
4
* This program is free software; you can redistribute it and/or modify
7
5
* it under the terms of the GNU General Public License as published by
30
28
#include "PlainTextFormat.h"
32
#include "../../FBOptions.h"
30
#include "../../options/FBOptions.h"
34
32
const std::string OPTION_Initialized = "Initialized";
35
33
const std::string OPTION_BreakType = "BreakType";
38
36
const std::string OPTION_CreateContentsTable = "CreateContentsTable";
40
38
PlainTextFormat::PlainTextFormat(const std::string &fileName) :
41
InitializedOption(FBOptions::BOOKS_CATEGORY, fileName, OPTION_Initialized, false),
42
BreakTypeOption(FBOptions::BOOKS_CATEGORY, fileName, OPTION_BreakType, 1),
43
IgnoredIndentOption(FBOptions::BOOKS_CATEGORY, fileName, OPTION_IgnoredIndent, 1, 100, 1),
44
EmptyLinesBeforeNewSectionOption(FBOptions::BOOKS_CATEGORY, fileName, OPTION_EmptyLinesBeforeNewSection, 1, 100, 1),
45
CreateContentsTableOption(FBOptions::BOOKS_CATEGORY, fileName, OPTION_CreateContentsTable, false) {
39
InitializedOption(FBCategoryKey::BOOKS, fileName, OPTION_Initialized, false),
40
BreakTypeOption(FBCategoryKey::BOOKS, fileName, OPTION_BreakType, 1),
41
IgnoredIndentOption(FBCategoryKey::BOOKS, fileName, OPTION_IgnoredIndent, 1, 100, 1),
42
EmptyLinesBeforeNewSectionOption(FBCategoryKey::BOOKS, fileName, OPTION_EmptyLinesBeforeNewSection, 1, 100, 1),
43
CreateContentsTableOption(FBCategoryKey::BOOKS, fileName, OPTION_CreateContentsTable, false) {
48
46
PlainTextInfoPage::PlainTextInfoPage(ZLOptionsDialog &dialog, const std::string &fileName, const ZLResourceKey &key, bool showContentsEntry) : myFormat(fileName) {
84
82
const unsigned int tableSize = 10;
86
84
unsigned int lineCounter = 0;
87
unsigned int emptyLineCounter = 0;
88
unsigned int libRuHeaderLineCounter = 0;
85
int emptyLineCounter = -1;
89
86
unsigned int stringsWithLengthLessThan81Counter = 0;
90
87
unsigned int stringIndentTable[tableSize] = { 0 };
91
88
unsigned int emptyLinesTable[tableSize] = { 0 };
92
89
unsigned int emptyLinesBeforeShortStringTable[tableSize] = { 0 };
94
91
bool currentLineIsEmpty = true;
95
bool currentLineIsLikeToLibRuHeader = false;
96
92
unsigned int currentLineLength = 0;
97
93
unsigned int currentLineIndent = 0;
98
unsigned int currentNumberOfEmptyLines = 0;
94
int currentNumberOfEmptyLines = -1;
100
96
char *buffer = new char[BUFFER_SIZE];
105
101
const char *end = buffer + length;
106
102
for (const char *ptr = buffer; ptr != end; ++ptr) {
107
103
++currentLineLength;
108
if ((*ptr == '\r') || ((*ptr == '\n') && (previous != '\r'))) {
104
if ((*ptr == '\n') || ((*ptr == '\r') && (previous != '\n'))) {
110
106
if (currentLineIsEmpty) {
111
107
++emptyLineCounter;
112
108
++currentNumberOfEmptyLines;
114
emptyLinesTable[std::min(currentNumberOfEmptyLines, tableSize - 1)]++;
115
if (currentLineLength < 51) {
116
emptyLinesBeforeShortStringTable[std::min(currentNumberOfEmptyLines, tableSize - 1)]++;
110
if (currentNumberOfEmptyLines >= 0) {
111
int index = std::min(currentNumberOfEmptyLines, (int)tableSize - 1);
112
emptyLinesTable[index]++;
113
if (currentLineLength < 51) {
114
emptyLinesBeforeShortStringTable[index]++;
118
currentNumberOfEmptyLines = 0;
120
if (currentLineIsLikeToLibRuHeader) {
121
++libRuHeaderLineCounter;
117
currentNumberOfEmptyLines = -1;
123
119
if (currentLineLength < 81) {
124
120
++stringsWithLengthLessThan81Counter;