~ubuntu-branches/ubuntu/vivid/fbreader/vivid-proposed

« back to all changes in this revision

Viewing changes to fbreader/src/formats/txt/PlainTextFormat.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Joey Hess
  • Date: 2008-01-23 16:51:07 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20080123165107-5q19etahzd72c33a
Tags: 0.8.12-3
* Add libzlui-maemo which allows using fbreader on the maemo platform, on
  Debian. Thanks, Riku Voipio. Closes: #462299
* makefiles/arch/maemo.mk: Don't build with -thumb. (Riku)
* Loosen dependency versions some more, so it only depends on the current
  upstream version or higher, ignoring the Debian revision.
* Use binary:Version instead of deprecated Source-Version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
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>
5
3
 *
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
29
27
 
30
28
#include "PlainTextFormat.h"
31
29
 
32
 
#include "../../FBOptions.h"
 
30
#include "../../options/FBOptions.h"
33
31
 
34
32
const std::string OPTION_Initialized = "Initialized";
35
33
const std::string OPTION_BreakType = "BreakType";
38
36
const std::string OPTION_CreateContentsTable = "CreateContentsTable";
39
37
 
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) {
46
44
}
47
45
 
48
46
PlainTextInfoPage::PlainTextInfoPage(ZLOptionsDialog &dialog, const std::string &fileName, const ZLResourceKey &key, bool showContentsEntry) : myFormat(fileName) {
84
82
        const unsigned int tableSize = 10;
85
83
 
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 };
93
90
 
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;
99
95
        
100
96
        char *buffer = new char[BUFFER_SIZE];
101
97
        int length;
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'))) {
109
105
                                ++lineCounter;
110
106
                                if (currentLineIsEmpty) {
111
107
                                        ++emptyLineCounter;
112
108
                                        ++currentNumberOfEmptyLines;
113
109
                                } else {
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]++;
 
115
                                                }
117
116
                                        }
118
 
                                        currentNumberOfEmptyLines = 0;
119
 
                                }
120
 
                                if (currentLineIsLikeToLibRuHeader) {
121
 
                                        ++libRuHeaderLineCounter;
 
117
                                        currentNumberOfEmptyLines = -1;
122
118
                                }
123
119
                                if (currentLineLength < 81) {
124
120
                                        ++stringsWithLengthLessThan81Counter;
127
123
                                        stringIndentTable[std::min(currentLineIndent, tableSize - 1)]++;
128
124
                                }
129
125
                                
130
 
                                currentLineIsLikeToLibRuHeader = currentLineIsEmpty;
131
126
                                currentLineIsEmpty = true;
132
127
                                currentLineLength = 0;
133
128
                                currentLineIndent = 0;
137
132
                                }
138
133
                        } else {
139
134
                                currentLineIsEmpty = false;
140
 
                                if (*ptr != '-') {
141
 
                                        currentLineIsLikeToLibRuHeader = false;
142
 
                                }
143
135
                        }
144
136
                        previous = *ptr;
145
137
                }