File indexing completed on 2024-09-01 03:47:37
0001 /* 0002 This file is part of the Kate project. 0003 SPDX-FileCopyrightText: 2010 Christoph Cullmann <cullmann@kde.org> 0004 SPDX-FileCopyrightText: 2010-2018 Dominik Haumann <dhaumann@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #include "katetextbuffer.h" 0010 #include <kateglobal.h> 0011 0012 #include <QCoreApplication> 0013 #include <qchar.h> 0014 0015 int main(int argc, char *argv[]) 0016 { 0017 // construct core app 0018 QCoreApplication app(argc, argv); 0019 0020 // test mode 0021 KTextEditor::EditorPrivate::enableUnitTestMode(); 0022 0023 // get arguments 0024 QString encoding = app.arguments().at(1); 0025 QString inFile = app.arguments().at(2); 0026 QString outFile = app.arguments().at(3); 0027 0028 Kate::TextBuffer buffer(nullptr); 0029 0030 // set codec 0031 buffer.setFallbackTextCodec(QString::fromUtf8(QStringConverter::nameForEncoding(QStringConverter::Latin1))); 0032 buffer.setTextCodec(encoding); 0033 0034 // switch to Mac EOL, this will test eol detection, as files are normal unix or dos 0035 buffer.setEndOfLineMode(Kate::TextBuffer::eolMac); 0036 0037 // load file 0038 bool encodingErrors = false; 0039 bool tooLongLines = false; 0040 int longestLineLoaded; 0041 if (!buffer.load(inFile, encodingErrors, tooLongLines, longestLineLoaded, false) || encodingErrors) { 0042 return 1; 0043 } 0044 0045 // save file 0046 if (!buffer.save(outFile)) { 0047 return 1; 0048 } 0049 0050 return 0; 0051 }