From 5b3c3ff97e1aeb76f8dc6abe0b4f9a6fd64f9fa5 Mon Sep 17 00:00:00 2001 From: Dimitrios Apostolou Date: Tue, 19 May 2020 18:05:53 +0200 Subject: Improve readability of the autogenerated arrays in qurltlds_p.h The next time qurltlds_p.h is generated, array sizes shall be explicit. Also added some helpful comments. And updated copyright date. Change-Id: I2bc9a78bcc2982845fce75a413e2048b0bfd12a0 Reviewed-by: Edward Welbourne --- util/corelib/qurl-generateTLDs/main.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'util') diff --git a/util/corelib/qurl-generateTLDs/main.cpp b/util/corelib/qurl-generateTLDs/main.cpp index 1e104e99c2..1f54299017 100644 --- a/util/corelib/qurl-generateTLDs/main.cpp +++ b/util/corelib/qurl-generateTLDs/main.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2019 The Qt Company Ltd. +** Copyright (C) 2020 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the utils of the Qt Toolkit. @@ -145,8 +145,12 @@ int main(int argc, char **argv) entry.append(st); entry.append("\\0"); } - outFile.write("static const quint32 tldIndices[] = {\n"); - outDataBuffer.write("\nstatic const char *tldData[] = {"); + + outFile.write("// After the tldCount \"real\" entries in tldIndices, include a final entry\n"); + outFile.write("// that records the sum of the lengths of all the chunks, i.e. the index\n"); + outFile.write("// just past the end of tldChunks.\n"); + outFile.write("static const quint32 tldIndices[tldCount + 1] = {\n"); + outDataBuffer.write("static const char *tldData[tldChunkCount] = {"); int totalUtf8Size = 0; int chunkSize = 0; // strlen of the current chunk (sizeof is bigger by 1) @@ -177,17 +181,23 @@ int main(int argc, char **argv) } } chunks.append(QString::number(totalUtf8Size)); + + // Write one extra entry, at tldIndices[tldCount], that contains the total size. outFile.write(QByteArray::number(totalUtf8Size)); outFile.write("\n};\n"); outDataBuffer.write("\n};\n"); outDataBuffer.close(); - outFile.write(outDataBufferBA); - // write chunk information + // First we have to define tldChunkCount. outFile.write("\nstatic const quint16 tldChunkCount = "); outFile.write(QByteArray::number(chunks.count())); - outFile.write(";\nstatic const quint32 tldChunks[] = {"); + outFile.write(";\n"); + + // Write tldData[tldChunkCount] = {...}. + outFile.write(outDataBufferBA); + + outFile.write("static const quint32 tldChunks[tldChunkCount] = {"); outFile.write(chunks.join(", ").toLatin1()); outFile.write("};\n"); outFile.close(); -- cgit v1.2.3