File indexing completed on 2024-12-08 04:17:52
0001 /* 0002 SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "indexeddatatable.h" 0008 0009 #include <QByteArray> 0010 #include <QString> 0011 0012 void StringTable::addString(const QString &s) 0013 { 0014 addEntry(s.toUtf8()); 0015 } 0016 0017 std::size_t StringTable::stringOffset(const QString &s) const 0018 { 0019 return entryOffset(s.toUtf8()); 0020 } 0021 0022 static void writeQuoted(const QByteArray &b, QIODevice *out) 0023 { 0024 for (char c : b) { 0025 switch (c) { 0026 case '"': 0027 case '\\': 0028 out->write("\\"); 0029 } 0030 out->write(&c, 1); 0031 } 0032 } 0033 0034 void StringTable::writeCode(const char* name, QIODevice *out) const 0035 { 0036 IndexedDataTable<QByteArray>::writeCode("char", name, out, [](const QByteArray &b, QIODevice *out) { 0037 out->write("\""); 0038 writeQuoted(b, out); 0039 out->write("\\0\""); 0040 }); 0041 }