Changeset View
Changeset View
Standalone View
Standalone View
src/metadata/poextractor.cpp
Show All 15 Lines | 1 | /* | |||
---|---|---|---|---|---|
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
17 | Lesser General Public License for more details. | 17 | Lesser General Public License for more details. | ||
18 | 18 | | |||
19 | You should have received a copy of the GNU Lesser General Public | 19 | You should have received a copy of the GNU Lesser General Public | ||
20 | License along with this library; if not, write to the Free Software | 20 | License along with this library; if not, write to the Free Software | ||
21 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | 21 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
22 | */ | 22 | */ | ||
23 | 23 | | |||
24 | | ||||
25 | #include "poextractor.h" | 24 | #include "poextractor.h" | ||
26 | 25 | | |||
27 | #include <fstream> | 26 | #include <fstream> | ||
28 | 27 | | |||
29 | #include <QFile> | 28 | #include <QFile> | ||
30 | 29 | | |||
31 | POExtractor::POExtractor() | 30 | POExtractor::POExtractor() | ||
32 | : state(WHITESPACE) | 31 | : state(WHITESPACE) | ||
▲ Show 20 Lines • Show All 87 Lines • ▼ Show 20 Line(s) | 112 | #if 0 | |||
120 | } else if (strncmp("\"PO-Revision-Date: ", data, 19) == 0) { | 119 | } else if (strncmp("\"PO-Revision-Date: ", data, 19) == 0) { | ||
121 | result->add(Property::TranslationLastUpDate, QByteArray(data + 19, length - 20)); | 120 | result->add(Property::TranslationLastUpDate, QByteArray(data + 19, length - 20)); | ||
122 | } else if (strncmp("\"Last-Translator: ", data, 18) == 0) { | 121 | } else if (strncmp("\"Last-Translator: ", data, 18) == 0) { | ||
123 | result->add(Property::TranslationLastAuthor, QByteArray(data + 18, length - 19)); | 122 | result->add(Property::TranslationLastAuthor, QByteArray(data + 18, length - 19)); | ||
124 | } | 123 | } | ||
125 | #endif | 124 | #endif | ||
126 | } | 125 | } | ||
127 | 126 | | |||
128 | void POExtractor::extract(const QString& filePath, FileMetaData& m) | 127 | FileMetaData POExtractor::extract(const QString& filePath) | ||
129 | { | 128 | { | ||
130 | std::ifstream fstream(QFile::encodeName(filePath)); | 129 | std::ifstream fstream(QFile::encodeName(filePath)); | ||
131 | if (!fstream.is_open()) { | 130 | if (!fstream.is_open()) { | ||
132 | return; | 131 | return {}; | ||
133 | } | 132 | } | ||
134 | 133 | | |||
135 | state = WHITESPACE; | 134 | state = WHITESPACE; | ||
136 | messages = 0; | 135 | messages = 0; | ||
137 | untranslated = 0; | 136 | untranslated = 0; | ||
138 | fuzzy = 0; | 137 | fuzzy = 0; | ||
139 | isFuzzy = false; | 138 | isFuzzy = false; | ||
140 | isTranslated = false; | 139 | isTranslated = false; | ||
141 | 140 | | |||
142 | std::string line; | 141 | std::string line; | ||
143 | int lines = 0; | 142 | int lines = 0; | ||
143 | FileMetaData m; | ||||
144 | while (std::getline(fstream, line)) { | 144 | while (std::getline(fstream, line)) { | ||
145 | //TODO add a parsed text of translation units | 145 | //TODO add a parsed text of translation units | ||
146 | //QByteArray arr = QByteArray::fromRawData(line.c_str(), line.size()); | 146 | //QByteArray arr = QByteArray::fromRawData(line.c_str(), line.size()); | ||
147 | //result->append(QString::fromUtf8(arr)); | 147 | //result->append(QString::fromUtf8(arr)); | ||
148 | 148 | | |||
149 | handleLine(line.c_str(), line.size()); | 149 | handleLine(line.c_str(), line.size()); | ||
150 | lines++; | 150 | lines++; | ||
151 | 151 | | |||
Show All 32 Lines | 182 | if (messages < 0 || fuzzy < 0 || untranslated < 0) { | |||
184 | m.translated = 0; | 184 | m.translated = 0; | ||
185 | m.untranslated = 0; | 185 | m.untranslated = 0; | ||
186 | m.fuzzy = 0; | 186 | m.fuzzy = 0; | ||
187 | } | 187 | } | ||
188 | 188 | | |||
189 | //TODO | 189 | //TODO | ||
190 | m.translated_approver = m.translated_reviewer = m.translated; | 190 | m.translated_approver = m.translated_reviewer = m.translated; | ||
191 | m.fuzzy_approver = m.fuzzy_reviewer = m.fuzzy; | 191 | m.fuzzy_approver = m.fuzzy_reviewer = m.fuzzy; | ||
192 | | ||||
193 | return m; | ||||
192 | } | 194 | } |