Inline cellkeywords.inl, and drop its generating machinery
Now that we have UTF-8-encoded CXX, we can simplify the initialization of ScCellKeywordTranslator, by inlining all the translation pairs. Change-Id: I5dedf71d5694c919f09c8c538bd4dba6cce391ee Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181010 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
This commit is contained in:
@@ -72,7 +72,6 @@ private:
|
||||
|
||||
void addToMap(const OUString& rKey, const char* pName, const css::lang::Locale& rLocale,
|
||||
OpCode eOpCode);
|
||||
void addToMap(const TransItem* pItems, const css::lang::Locale& rLocale);
|
||||
|
||||
static ::std::unique_ptr<ScCellKeywordTranslator> spInstance;
|
||||
ScCellKeywordHashMap maStringNameMap;
|
||||
|
||||
@@ -182,17 +182,85 @@ ScCellKeywordTranslator::ScCellKeywordTranslator() :
|
||||
maTransWrapper( ::comphelper::getProcessComponentContext(),
|
||||
TransliterationFlags::LOWERCASE_UPPERCASE )
|
||||
{
|
||||
// The file below has been autogenerated by sc/workben/celltrans/parse.py.
|
||||
// To add new locale keywords, edit sc/workben/celltrans/keywords_utf16.txt
|
||||
// and re-run the parse.py script.
|
||||
//
|
||||
// All keywords must be uppercase, and the mapping must be from the
|
||||
// localized keyword to the English keyword.
|
||||
//
|
||||
// Make sure that the original keyword file (keywords_utf16.txt) is
|
||||
// encoded in UCS-2/UTF-16!
|
||||
|
||||
#include "cellkeywords.inl"
|
||||
// French language locale
|
||||
|
||||
static const lang::Locale aFr(u"fr"_ustr, u""_ustr, u""_ustr);
|
||||
|
||||
static const TransItem pFr[] = {
|
||||
{ u"ADRESSE", "ADDRESS", ocCell },
|
||||
{ u"COLONNE", "COL", ocCell },
|
||||
{ u"CONTENU", "CONTENTS", ocCell },
|
||||
{ u"COULEUR", "COLOR", ocCell },
|
||||
{ u"LARGEUR", "WIDTH", ocCell },
|
||||
{ u"LIGNE", "ROW", ocCell },
|
||||
{ u"NOMFICHIER", "FILENAME", ocCell },
|
||||
{ u"PREFIXE", "PREFIX", ocCell },
|
||||
{ u"PROTEGE", "PROTECT", ocCell },
|
||||
{ u"NBFICH", "NUMFILE", ocInfo },
|
||||
{ u"RECALCUL", "RECALC", ocInfo },
|
||||
{ u"SYSTEXPL", "SYSTEM", ocInfo },
|
||||
{ u"VERSION", "RELEASE", ocInfo },
|
||||
{ u"VERSIONSE", "OSVERSION", ocInfo },
|
||||
};
|
||||
|
||||
for (const auto& element : pFr)
|
||||
addToMap(OUString(element.from), element.to, aFr, element.func);
|
||||
|
||||
// Hungarian language locale
|
||||
|
||||
static const lang::Locale aHu(u"hu"_ustr, u""_ustr, u""_ustr);
|
||||
|
||||
static const TransItem pHu[] = {
|
||||
{ u"CÍM", "ADDRESS", ocCell },
|
||||
{ u"OSZLOP", "COL", ocCell },
|
||||
{ u"SZÍN", "COLOR", ocCell },
|
||||
{ u"TARTALOM", "CONTENTS", ocCell },
|
||||
{ u"SZÉLES", "WIDTH", ocCell },
|
||||
{ u"SOR", "ROW", ocCell },
|
||||
{ u"FILENÉV", "FILENAME", ocCell },
|
||||
{ u"PREFIX", "PREFIX", ocCell },
|
||||
{ u"VÉDETT", "PROTECT", ocCell },
|
||||
{ u"KOORD", "COORD", ocCell },
|
||||
{ u"FORMA", "FORMAT", ocCell },
|
||||
{ u"ZÁRÓJELEK", "PARENTHESES", ocCell },
|
||||
{ u"LAP", "SHEET", ocCell },
|
||||
{ u"TÍPUS", "TYPE", ocCell },
|
||||
{ u"FILESZÁM", "NUMFILE", ocInfo },
|
||||
{ u"SZÁMOLÁS", "RECALC", ocInfo },
|
||||
{ u"RENDSZER", "SYSTEM", ocInfo },
|
||||
{ u"VERZIÓ", "RELEASE", ocInfo },
|
||||
{ u"OPRENDSZER", "OSVERSION", ocInfo },
|
||||
};
|
||||
|
||||
for (const auto& element : pHu)
|
||||
addToMap(OUString(element.from), element.to, aHu, element.func);
|
||||
|
||||
// German language locale
|
||||
|
||||
static const lang::Locale aDe(u"de"_ustr, u""_ustr, u""_ustr);
|
||||
|
||||
static const TransItem pDe[] = {
|
||||
{ u"ZEILE", "ROW", ocCell },
|
||||
{ u"SPALTE", "COL", ocCell },
|
||||
{ u"BREITE", "WIDTH", ocCell },
|
||||
{ u"ADRESSE", "ADDRESS", ocCell },
|
||||
{ u"DATEINAME", "FILENAME", ocCell },
|
||||
{ u"FARBE", "COLOR", ocCell },
|
||||
{ u"FORMAT", "FORMAT", ocCell },
|
||||
{ u"INHALT", "CONTENTS", ocCell },
|
||||
{ u"KLAMMERN", "PARENTHESES", ocCell },
|
||||
{ u"SCHUTZ", "PROTECT", ocCell },
|
||||
{ u"TYP", "TYPE", ocCell },
|
||||
{ u"PRÄFIX", "PREFIX", ocCell },
|
||||
{ u"BLATT", "SHEET", ocCell },
|
||||
{ u"KOORD", "COORD", ocCell },
|
||||
};
|
||||
|
||||
for (const auto& element : pDe)
|
||||
addToMap(OUString(element.from), element.to, aDe, element.func);
|
||||
}
|
||||
|
||||
ScCellKeywordTranslator::~ScCellKeywordTranslator()
|
||||
@@ -216,10 +284,4 @@ void ScCellKeywordTranslator::addToMap(const OUString& rKey, const char* pName,
|
||||
itr->second.push_back(aKeyItem);
|
||||
}
|
||||
|
||||
void ScCellKeywordTranslator::addToMap(const TransItem* pItems, const lang::Locale& rLocale)
|
||||
{
|
||||
for (sal_uInt16 i = 0; pItems[i].from != nullptr; ++i)
|
||||
addToMap(OUString(pItems[i].from), pItems[i].to, rLocale, pItems[i].func);
|
||||
}
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
|
||||
@@ -1,99 +0,0 @@
|
||||
/*
|
||||
* This file is part of the LibreOffice project.
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* This file incorporates work covered by the following license notice:
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed
|
||||
* with this work for additional information regarding copyright
|
||||
* ownership. The ASF licenses this file to you under the Apache
|
||||
* License, Version 2.0 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
||||
*/
|
||||
|
||||
// This file has been automatically generated. Do not hand-edit this!
|
||||
|
||||
|
||||
// French language locale (automatically generated)
|
||||
|
||||
static const lang::Locale aFr(u"fr"_ustr, u""_ustr, u""_ustr);
|
||||
|
||||
static const TransItem pFr[] = {
|
||||
{u"ADRESSE", "ADDRESS", ocCell},
|
||||
{u"COLONNE", "COL", ocCell},
|
||||
{u"CONTENU", "CONTENTS", ocCell},
|
||||
{u"COULEUR", "COLOR", ocCell},
|
||||
{u"LARGEUR", "WIDTH", ocCell},
|
||||
{u"LIGNE", "ROW", ocCell},
|
||||
{u"NOMFICHIER", "FILENAME", ocCell},
|
||||
{u"PREFIXE", "PREFIX", ocCell},
|
||||
{u"PROTEGE", "PROTECT", ocCell},
|
||||
{u"NBFICH", "NUMFILE", ocInfo},
|
||||
{u"RECALCUL", "RECALC", ocInfo},
|
||||
{u"SYSTEXPL", "SYSTEM", ocInfo},
|
||||
{u"VERSION", "RELEASE", ocInfo},
|
||||
{u"VERSIONSE", "OSVERSION", ocInfo},
|
||||
{nullptr, nullptr, ocNone}
|
||||
};
|
||||
|
||||
addToMap(pFr, aFr);
|
||||
|
||||
|
||||
// Hungarian language locale (automatically generated)
|
||||
|
||||
static const lang::Locale aHu(u"hu"_ustr, u""_ustr, u""_ustr);
|
||||
|
||||
static const TransItem pHu[] = {
|
||||
{u"CÍM", "ADDRESS", ocCell},
|
||||
{u"OSZLOP", "COL", ocCell},
|
||||
{u"SZÍN", "COLOR", ocCell},
|
||||
{u"TARTALOM", "CONTENTS", ocCell},
|
||||
{u"SZÉLES", "WIDTH", ocCell},
|
||||
{u"SOR", "ROW", ocCell},
|
||||
{u"FILENÉV", "FILENAME", ocCell},
|
||||
{u"PREFIX", "PREFIX", ocCell},
|
||||
{u"VÉDETT", "PROTECT", ocCell},
|
||||
{u"KOORD", "COORD", ocCell},
|
||||
{u"FORMA", "FORMAT", ocCell},
|
||||
{u"ZÁRÓJELEK", "PARENTHESES", ocCell},
|
||||
{u"LAP", "SHEET", ocCell},
|
||||
{u"TÍPUS", "TYPE", ocCell},
|
||||
{u"FILESZÁM", "NUMFILE", ocInfo},
|
||||
{u"SZÁMOLÁS", "RECALC", ocInfo},
|
||||
{u"RENDSZER", "SYSTEM", ocInfo},
|
||||
{u"VERZIÓ", "RELEASE", ocInfo},
|
||||
{u"OPRENDSZER", "OSVERSION", ocInfo},
|
||||
{nullptr, nullptr, ocNone}
|
||||
};
|
||||
|
||||
addToMap(pHu, aHu);
|
||||
|
||||
|
||||
// German language locale (automatically generated)
|
||||
|
||||
static const lang::Locale aDe(u"de"_ustr, u""_ustr, u""_ustr);
|
||||
|
||||
static const TransItem pDe[] = {
|
||||
{u"ZEILE", "ROW", ocCell},
|
||||
{u"SPALTE", "COL", ocCell},
|
||||
{u"BREITE", "WIDTH", ocCell},
|
||||
{u"ADRESSE", "ADDRESS", ocCell},
|
||||
{u"DATEINAME", "FILENAME", ocCell},
|
||||
{u"FARBE", "COLOR", ocCell},
|
||||
{u"FORMAT", "FORMAT", ocCell},
|
||||
{u"INHALT", "CONTENTS", ocCell},
|
||||
{u"KLAMMERN", "PARENTHESES", ocCell},
|
||||
{u"SCHUTZ", "PROTECT", ocCell},
|
||||
{u"TYP", "TYPE", ocCell},
|
||||
{u"PRÄFIX", "PREFIX", ocCell},
|
||||
{u"BLATT", "SHEET", ocCell},
|
||||
{u"KOORD", "COORD", ocCell},
|
||||
{nullptr, nullptr, ocNone}
|
||||
};
|
||||
|
||||
addToMap(pDe, aDe);
|
||||
Binary file not shown.
@@ -1,202 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# This file is part of the LibreOffice project.
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# This file incorporates work covered by the following license notice:
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
# contributor license agreements. See the NOTICE file distributed
|
||||
# with this work for additional information regarding copyright
|
||||
# ownership. The ASF licenses this file to you under the Apache
|
||||
# License, Version 2.0 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
||||
#
|
||||
|
||||
import sys
|
||||
|
||||
localeNames = {'fr': 'French', 'hu': 'Hungarian', 'de': 'German'}
|
||||
def getLocaleName (code):
|
||||
global localeNames
|
||||
if code in localeNames:
|
||||
return localeNames[code]
|
||||
else:
|
||||
return "(unknown locale)"
|
||||
|
||||
def getAscii (ords):
|
||||
ascii = ''
|
||||
for c in ords:
|
||||
ascii += chr(c)
|
||||
return ascii
|
||||
|
||||
class LocaleData(object):
|
||||
def __init__ (self, locale):
|
||||
self.locale = locale
|
||||
self.funcList = {}
|
||||
|
||||
def addKeywordMap (self, funcName, localeName, engName):
|
||||
if funcName not in self.funcList:
|
||||
self.funcList[funcName] = []
|
||||
|
||||
self.funcList[funcName].append([localeName, engName])
|
||||
|
||||
def getLocaleFuncVarName (self, func, pair):
|
||||
return func.lower() + "_" + getAscii(pair[1]).lower() + "_" + self.locale
|
||||
|
||||
def dumpCode (self):
|
||||
chars = ""
|
||||
|
||||
# locale output
|
||||
chars += "// " + "-"*75 + "\n"
|
||||
chars += "// %s language locale (automatically generated)\n"%getLocaleName(self.locale)
|
||||
chars += "// " + "-"*75 + "\n"
|
||||
chars += "static const Locale a" + self.locale.capitalize() + "(OUString(\""
|
||||
chars += self.locale
|
||||
chars += "\"), OUString(), OUString());\n\n"
|
||||
|
||||
# pre instantiations of localized function names.
|
||||
funcs = sorted(self.funcList.keys())
|
||||
chars += "// pre instantiations of localized function names\n"
|
||||
for func in funcs:
|
||||
for item in self.funcList[func]:
|
||||
chars += "static const sal_Unicode " + self.getLocaleFuncVarName(func, item) + "[] = {\n"
|
||||
chars += " "
|
||||
isFirst = True
|
||||
# Dump the UTF-16 bytes.
|
||||
for uval in item[0]:
|
||||
if isFirst:
|
||||
isFirst = False
|
||||
else:
|
||||
chars += ", "
|
||||
chars += "0x%.4X"%uval
|
||||
|
||||
# Don't forget to null-terminate the string.
|
||||
if not isFirst:
|
||||
chars += ", "
|
||||
chars += "0x0000"
|
||||
|
||||
chars += "};\n"
|
||||
|
||||
# map item instantiations
|
||||
chars += "\n"
|
||||
chars += "static const TransItem p" + self.locale.capitalize() + "[] = {\n"
|
||||
for func in funcs:
|
||||
for item in self.funcList[func]:
|
||||
chars += " "
|
||||
chars += "{%s, \"%s\", %s},\n"%(self.getLocaleFuncVarName(func, item),
|
||||
getAscii(item[1]),
|
||||
"oc"+func.capitalize())
|
||||
|
||||
chars += " {NULL, NULL, ocNone}\n"
|
||||
chars += "};\n\n"
|
||||
|
||||
# addToMap call
|
||||
chars += "addToMap(%s, %s);\n"%(
|
||||
"p"+self.locale.capitalize(), "a"+self.locale.capitalize())
|
||||
|
||||
return chars
|
||||
|
||||
class Parser(object):
|
||||
|
||||
def __init__ (self, args):
|
||||
# default input & output files.
|
||||
self.infile = "./keywords_utf16.txt"
|
||||
self.outfile = "../../source/core/tool/cellkeywords.inl"
|
||||
|
||||
if len(args) >= 2:
|
||||
self.infile = args[1]
|
||||
if len(args) >= 3:
|
||||
self.outfile = args[2]
|
||||
|
||||
def getDByte (self):
|
||||
# Assume little endian.
|
||||
bh = self.bytes[self.i]
|
||||
bl = self.bytes[self.i+1]
|
||||
try:
|
||||
dbyte = ord(bl)*256 + ord(bh)
|
||||
except Exception:
|
||||
dbyte = bl*256 + bh
|
||||
self.i += 2
|
||||
return dbyte
|
||||
|
||||
def parseLine (self):
|
||||
buf = []
|
||||
while self.i < self.size:
|
||||
dbyte = self.getDByte()
|
||||
if dbyte == 0x000A:
|
||||
break
|
||||
buf.append(dbyte)
|
||||
return buf
|
||||
|
||||
def dumpBuf (self, buf, linefeed=True):
|
||||
for item in buf:
|
||||
sys.stdout.write(chr(item))
|
||||
if linefeed:
|
||||
print ('')
|
||||
|
||||
def parse (self):
|
||||
|
||||
file = open(self.infile, 'rb')
|
||||
self.bytes = file.read()
|
||||
file.close()
|
||||
|
||||
self.size = len(self.bytes)
|
||||
self.i = 0
|
||||
|
||||
localeList = [] # stores an array of locale data objects.
|
||||
funcName = None
|
||||
word = []
|
||||
wordPair = []
|
||||
|
||||
while self.i < self.size:
|
||||
dbyte = self.getDByte()
|
||||
if dbyte == 0xFEFF and self.i == 2:
|
||||
# unicode signature - ignore it.
|
||||
pass
|
||||
elif dbyte == 0x0024:
|
||||
# $ - locale name
|
||||
buf = self.parseLine()
|
||||
locale = getAscii(buf)
|
||||
localeList.append(LocaleData(locale))
|
||||
|
||||
elif dbyte == 0x0040:
|
||||
# @ - function name
|
||||
buf = self.parseLine()
|
||||
funcName = getAscii(buf)
|
||||
|
||||
elif dbyte == 0x002C:
|
||||
# , - comma separator
|
||||
if len(word) > 0:
|
||||
wordPair.append(word)
|
||||
word = []
|
||||
elif dbyte == 0x000A:
|
||||
# linefeed
|
||||
if len(word) > 0:
|
||||
wordPair.append(word)
|
||||
word = []
|
||||
if len(wordPair) >= 2:
|
||||
localeList[-1].addKeywordMap(funcName, wordPair[0], wordPair[1])
|
||||
wordPair = []
|
||||
elif dbyte in [0x0009, 0x0020]:
|
||||
# whitespace - ignore it.
|
||||
pass
|
||||
else:
|
||||
word.append(dbyte)
|
||||
|
||||
chars = "// This file has been automatically generated. Do not hand-edit this!\n"
|
||||
for obj in localeList:
|
||||
chars += "\n" + obj.dumpCode()
|
||||
|
||||
# Write to output file.
|
||||
file = open(self.outfile, 'w')
|
||||
file.write(chars)
|
||||
file.close()
|
||||
|
||||
if __name__=='__main__':
|
||||
parser = Parser(sys.argv)
|
||||
parser.parse()
|
||||
|
||||
Reference in New Issue
Block a user