3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
7 * \author Jean-Marc Lasgouttes
10 * Full author contact details are available in file CREDITS.
19 #include "support/debug.h"
20 #include "support/docstring.h"
21 #include "support/gettext.h"
22 #include "support/lstrings.h"
23 #include "support/mutex.h"
24 #include "support/textutils.h"
25 #include "support/unicode.h"
33 using namespace lyx::support;
37 int const Encoding::any = -1;
41 Encodings::MathCommandSet Encodings::mathcmd;
42 Encodings::TextCommandSet Encodings::textcmd;
43 Encodings::MathSymbolSet Encodings::mathsym;
47 typedef map<char_type, CharInfo> CharInfoMap;
48 CharInfoMap unicodesymbols;
50 typedef set<char_type> CharSet;
51 typedef map<string, CharSet> CharSetMap;
53 CharSetMap forcedselected;
55 typedef set<char_type> MathAlphaSet;
56 MathAlphaSet mathalpha;
59 /// The highest code point in UCS4 encoding (1<<20 + 1<<16)
60 char_type const max_ucs4 = 0x110000;
65 EncodingException::EncodingException(char_type c)
66 : failed_char(c), par_id(0), pos(0)
71 const char * EncodingException::what() const noexcept
73 return "Could not find LaTeX command for a character";
78 docstring const & text_command, docstring const & math_command,
79 std::string const & text_preamble, std::string const & math_preamble,
80 std::string const & tipa_shortcut, unsigned int flags)
81 : text_commands_({text_command}), math_commands_({math_command}),
82 text_preamble_(text_preamble), math_preamble_(math_preamble),
83 tipa_shortcut_(tipa_shortcut), flags_(flags)
89 std::vector<docstring> const & text_commands, std::vector<docstring> const & math_commands,
90 std::string const & text_preamble, std::string const & math_preamble,
91 std::string const & tipa_shortcut, unsigned int flags)
92 : text_commands_(text_commands), math_commands_(math_commands),
93 text_preamble_(text_preamble), math_preamble_(math_preamble),
94 tipa_shortcut_(tipa_shortcut), flags_(flags)
99 Encoding::Encoding(string const & n, string const & l, string const & g,
100 string const & i, bool f, bool u, Encoding::Package p)
101 : name_(n), latexName_(l), guiName_(g), iconvName_(i), fixedwidth_(f),
102 unsafe_(u), forced_(&forcedselected[n]), package_(p)
105 // ASCII can encode 128 code points and nothing else
106 start_encodable_ = 128;
108 } else if (i == "UTF-8") {
109 // UTF8 can encode all UCS4 code points
110 start_encodable_ = max_ucs4;
113 start_encodable_ = 0;
119 void Encoding::init() const
121 // Since the the constructor is the only method which sets complete_
122 // to false the test for complete_ is thread-safe without mutex.
127 Mutex::Locker lock(&mutex);
129 // We need to test again for complete_, since another thread could
130 // have set it to true while we were waiting for the lock and we must
131 // not modify an encoding which is already complete.
135 // We do not make any member mutable so that it can be easily verified
136 // that all const methods are thread-safe: init() is the only const
137 // method which changes complete_, encodable_ and start_encodable_, and
138 // it uses a mutex to ensure thread-safety.
139 CharSet & encodable = const_cast<Encoding *>(this)->encodable_;
140 char_type & start_encodable = const_cast<Encoding *>(this)->start_encodable_;
143 // temporarily switch off lyxerr, since we will generate iconv errors
146 // We do not need to check all UCS4 code points, it is enough
147 // if we check all 256 code points of this encoding.
148 for (unsigned short j = 0; j < 256; ++j) {
149 char const c = char(j);
150 vector<char_type> const ucs4 = eightbit_to_ucs4(&c, 1, iconvName_);
151 if (ucs4.size() != 1)
153 char_type const uc = ucs4[0];
154 CharInfoMap::const_iterator const it = unicodesymbols.find(uc);
155 if (it == unicodesymbols.end())
156 encodable.insert(uc);
157 else if (!it->second.force()) {
158 if (forced_->empty() || forced_->find(uc) == forced_->end())
159 encodable.insert(uc);
163 // We do not know how many code points this encoding has, and
164 // they do not have a direct representation as a single byte,
165 // therefore we need to check all UCS4 code points.
166 // This is expensive!
167 for (char_type c = 0; c < max_ucs4; ++c) {
168 vector<char> const eightbit = ucs4_to_eightbit(&c, 1, iconvName_);
169 if (!eightbit.empty()) {
170 CharInfoMap::const_iterator const it = unicodesymbols.find(c);
171 if (it == unicodesymbols.end())
173 else if (!it->second.force()) {
174 if (forced_->empty() || forced_->find(c) == forced_->end())
181 CharSet::iterator it = encodable.find(start_encodable);
182 while (it != encodable.end()) {
185 it = encodable.find(start_encodable);
187 const_cast<Encoding *>(this)->complete_ = true;
191 bool Encoding::isForced(char_type c) const
193 if (!forced.empty() && forced.find(c) != forced.end())
195 return !forced_->empty() && forced_->find(c) != forced_->end();
199 bool Encoding::encodable(char_type c) const
201 // assure the used encoding is properly initialized
203 if (iconvName_ == "UTF-8" && package_ == none)
205 // platex does not load inputenc: force conversion of supported characters
206 if (package_ == Encoding::japanese
207 && ((0xb7 <= c && c <= 0x05ff) // Latin-1 Supplement ... Hebrew
208 || (0x1d00 <= c && c <= 0x218f) // Phonetic Extensions ... Number Forms
209 || (0x2193 <= c && c <= 0x2aff) // Arrows ... Supplemental Mathematical Operators
210 || (0xfb00 <= c && c <= 0xfb4f) // Alphabetic Presentation Forms
211 || (0x1d400 <= c && c <= 0x1d7ff))) // Mathematical Alphanumeric Symbols
213 if (c < start_encodable_ && !isForced(c))
215 if (encodable_.find(c) != encodable_.end())
221 pair<docstring, bool> Encoding::latexChar(char_type c) const
224 return make_pair(docstring(1, c), false);
226 // c cannot (or should not) be encoded in this encoding
227 CharInfoMap::const_iterator const it = unicodesymbols.find(c);
228 if (it == unicodesymbols.end())
229 throw EncodingException(c);
230 // at least one of mathCommand and textCommand is nonempty
231 if (it->second.textCommand().empty())
233 "\\ensuremath{" + it->second.mathCommand() + '}', false);
234 return make_pair(it->second.textCommand(), !it->second.textNoTermination());
238 pair<docstring, docstring> Encoding::latexString(docstring const & input, bool dryrun) const
242 bool terminate = false;
243 for (char_type const c : input) {
245 pair<docstring, bool> latex_char = latexChar(c);
246 docstring const latex = latex_char.first;
247 if (terminate && !prefixIs(latex, '\\')
248 && !prefixIs(latex, '{')
249 && !prefixIs(latex, '}')) {
250 // Prevent eating of a following
251 // space or command corruption by
252 // following characters
259 terminate = latex_char.second;
260 } catch (EncodingException & /* e */) {
261 LYXERR0("Uncodable character <" << docstring(1, c)
262 << "> in latexString!");
264 result += "<" + _("LyX Warning: ")
265 + _("uncodable character") + " '";
266 result += docstring(1, c);
272 return make_pair(result, uncodable);
276 vector<char_type> Encoding::symbolsList() const
278 // assure the used encoding is properly initialized
281 // first all those below start_encodable_
282 vector<char_type> symbols;
283 for (char_type c = 0; c < start_encodable_; ++c)
284 symbols.push_back(c);
285 // add all encodable characters
286 copy(encodable_.begin(), encodable_.end(), back_inserter(symbols));
287 // now the ones from the unicodesymbols file that are not already there
288 for (auto const & elem : unicodesymbols) {
289 if (find(symbols.begin(), symbols.end(), elem.first) == symbols.end())
290 symbols.push_back(elem.first);
292 // finally, sort the vector
293 sort(symbols.begin(), symbols.end());
298 bool Encodings::latexMathChar(char_type c, bool mathmode,
299 Encoding const * encoding, docstring & command,
300 bool & needsTermination)
302 command = empty_docstring();
304 if (encoding->encodable(c))
305 command = docstring(1, c);
306 needsTermination = false;
308 CharInfoMap::const_iterator const it = unicodesymbols.find(c);
309 if (it == unicodesymbols.end()) {
310 if (!encoding || command.empty())
311 throw EncodingException(c);
316 // at least one of mathCommand and textCommand is nonempty
317 bool use_math = (mathmode && !it->second.mathCommand().empty()) ||
318 (!mathmode && it->second.textCommand().empty());
320 command = it->second.mathCommand();
321 needsTermination = !it->second.mathNoTermination();
324 if (!encoding || command.empty()) {
325 command = it->second.textCommand();
326 needsTermination = !it->second.textNoTermination();
337 char_type Encodings::fromLaTeXCommand(docstring const & cmd, int cmdtype,
338 bool & combining, bool & needsTermination, set<string> * req)
340 CharInfoMap::const_iterator const end = unicodesymbols.end();
341 CharInfoMap::const_iterator it = unicodesymbols.begin();
342 for (combining = false; it != end; ++it) {
343 if (it->second.deprecated())
346 if (cmdtype & MATH_CMD) {
347 for (const docstring& math : it->second.mathCommands()) {
348 if ((cmdtype & MATH_CMD) && math == cmd) {
349 combining = it->second.combining();
350 needsTermination = !it->second.mathNoTermination();
351 if (req && it->second.mathFeature() &&
352 !it->second.mathPreamble().empty())
353 req->insert(it->second.mathPreamble());
359 if (cmdtype & TEXT_CMD) {
360 for (const docstring& text : it->second.textCommands()) {
362 combining = it->second.combining();
363 needsTermination = !it->second.textNoTermination();
364 if (req && it->second.textFeature() &&
365 !it->second.textPreamble().empty())
366 req->insert(it->second.textPreamble());
372 needsTermination = false;
377 docstring Encodings::fromLaTeXCommand(docstring const & cmd, int cmdtype,
378 bool & needsTermination, docstring & rem, set<string> * req)
380 needsTermination = false;
381 rem = empty_docstring();
382 bool const mathmode = cmdtype & MATH_CMD;
383 bool const textmode = cmdtype & TEXT_CMD;
385 size_t const cmdend = cmd.size();
387 CharInfoMap::const_iterator const uniend = unicodesymbols.end();
388 for (size_t i = 0, j = 0; j < cmdend; ++j) {
389 // Also get the char after a backslash
390 if (j + 1 < cmdend && cmd[j] == '\\') {
393 // Detect things like \=*{e} as well
394 if (j + 3 < cmdend && cmd[j+1] == '*' &&
400 // position of the last character before a possible macro
403 // If a macro argument follows, get it, too
404 // Do it here only for single character commands. Other
405 // combining commands need this too, but they are handled in
406 // the loop below for performance reasons.
407 if (j + 1 < cmdend && cmd[j + 1] == '{') {
410 while (k < cmdend && count) {
411 k = cmd.find_first_of(from_ascii("{}"), k + 1);
412 // braces may not be balanced
413 if (k == docstring::npos)
420 if (k != docstring::npos)
422 } else if (m + 1 < cmdend && isAlphaASCII(cmd[m])) {
423 while (m + 2 < cmdend && isAlphaASCII(cmd[m+1]))
426 // Start with this substring and try augmenting it when it is
427 // the prefix of some command in the unicodesymbols file
428 docstring subcmd = cmd.substr(i, j - i + 1);
430 CharInfoMap::const_iterator it = unicodesymbols.begin();
431 // First part of subcmd which might be a combining character
432 docstring combcmd = (m == j) ? docstring() : cmd.substr(i, m - i + 1);
433 // The combining character of combcmd if it exists
434 CharInfoMap::const_iterator combining = uniend;
435 size_t unicmd_size = 0;
437 for (; it != uniend; ++it) {
438 if (it->second.deprecated())
440 docstring const math = mathmode ? it->second.mathCommand()
442 docstring const text = textmode ? it->second.textCommand()
444 if (!combcmd.empty() && it->second.combining() &&
445 (math == combcmd || text == combcmd))
447 size_t cur_size = max(math.size(), text.size());
448 // The current math or text unicode command cannot
449 // match, or we already matched a longer one
450 if (cur_size < subcmd.size() || cur_size <= unicmd_size)
453 docstring tmp = subcmd;
455 while (prefixIs(math, tmp) || prefixIs(text, tmp)) {
457 if (k >= cmdend || cur_size <= tmp.size())
465 // The last added char caused a mismatch, because
466 // we didn't exhaust the chars in cmd and didn't
467 // exceed the maximum size of the current unicmd
468 if (k < cmdend && cur_size > tmp.size())
469 tmp.resize(tmp.size() - 1);
471 // If this is an exact match, we found a (longer)
472 // matching entry in the unicodesymbols file.
473 if (math != tmp && text != tmp)
475 // If we found a combining command, we need to append
476 // the macro argument if this has not been done above.
477 if (tmp == combcmd && combining != uniend &&
478 k < cmdend && cmd[k] == '{') {
481 while (l < cmdend && count) {
482 l = cmd.find_first_of(from_ascii("{}"), l + 1);
483 // braces may not be balanced
484 if (l == docstring::npos)
491 if (l != docstring::npos) {
493 subcmd = cmd.substr(i, j - i + 1);
496 // If the entry doesn't start with '\', we take note
497 // of the match and continue (this is not a ultimate
498 // acceptance, as some other entry may match a longer
499 // portion of the cmd string). However, if the entry
500 // does start with '\', we accept the match only if
501 // this is a valid macro, i.e., either it is a single
502 // (nonletter) char macro, or nothing else follows,
503 // or what follows is a nonletter char, or the last
505 else if (tmp[0] != '\\'
506 || (tmp.size() == prefix + 1 &&
507 !isAlphaASCII(tmp[1]) &&
508 (prefix == 1 || !isAlphaASCII(tmp[2])))
510 || !isAlphaASCII(cmd[k])
511 || tmp[tmp.size() - 1] == '}'
516 unicmd_size = cur_size;
518 needsTermination = !it->second.mathNoTermination();
520 needsTermination = !it->second.textNoTermination();
522 if (math == tmp && it->second.mathFeature() &&
523 !it->second.mathPreamble().empty())
524 req->insert(it->second.mathPreamble());
525 if (text == tmp && it->second.textFeature() &&
526 !it->second.textPreamble().empty())
527 req->insert(it->second.textPreamble());
533 else if (combining != uniend &&
534 prefixIs(subcmd, combcmd + '{')) {
535 // We know that subcmd starts with combcmd and
536 // contains an argument in braces.
537 docstring const arg = subcmd.substr(
538 combcmd.length() + 1,
539 subcmd.length() - combcmd.length() - 2);
540 // If arg is a single character we can construct a
541 // combining sequence.
543 bool argcomb = false;
544 if (arg.size() == 1 && isAlnumASCII(arg[0]))
547 // Use the version of fromLaTeXCommand() that
548 // parses only one command, since we cannot
549 // use more than one character.
552 a = fromLaTeXCommand(arg, cmdtype, argcomb,
554 if (a && req && !argcomb)
555 req->insert(r.begin(), r.end());
558 // In unicode the combining character comes
561 symbols += combining->first;
566 if (j + 1 == cmdend && !unicmd_size) {
567 // No luck. Return what remains
569 if (needsTermination && !rem.empty()) {
570 if (rem.substr(0, 2) == "{}") {
572 needsTermination = false;
573 } else if (rem[0] == ' ') {
574 needsTermination = false;
575 // LaTeX would swallow all spaces
585 CharInfo const & Encodings::unicodeCharInfo(char_type c)
587 static CharInfo empty;
588 CharInfoMap::const_iterator const it = unicodesymbols.find(c);
589 return it != unicodesymbols.end() ? it->second : empty;
593 bool Encodings::isCombiningChar(char_type c)
595 CharInfoMap::const_iterator const it = unicodesymbols.find(c);
596 if (it != unicodesymbols.end())
597 return it->second.combining();
602 string const Encodings::TIPAShortcut(char_type c)
604 CharInfoMap::const_iterator const it = unicodesymbols.find(c);
605 if (it != unicodesymbols.end())
606 return it->second.tipaShortcut();
611 string const Encodings::isKnownScriptChar(char_type const c)
613 CharInfoMap::const_iterator const it = unicodesymbols.find(c);
615 if (it == unicodesymbols.end())
617 // FIXME: parse complex textPreamble (may be list or alternatives,
618 // e.g., "subscript,textgreek" or "textcomp|textgreek")
619 if (it->second.textPreamble() == "textgreek"
620 || it->second.textPreamble() == "textcyrillic")
621 return it->second.textPreamble();
626 bool Encodings::fontencSupportsScript(string const & fontenc, string const & script)
628 if (script == "textgreek")
629 return (fontenc == "LGR" || fontenc == "TU");
630 if (script == "textcyrillic")
631 return (fontenc == "T2A" || fontenc == "T2B" || fontenc == "T2C"
632 || fontenc == "X2" || fontenc == "TU");
637 bool Encodings::isMathAlpha(char_type c)
639 return mathalpha.count(c);
643 bool Encodings::isUnicodeTextOnly(char_type c)
645 if (isASCII(c) || isMathAlpha(c))
648 CharInfoMap::const_iterator const it = unicodesymbols.find(c);
649 return it == unicodesymbols.end() || it->second.mathCommand().empty();
654 Encodings::fromLyXName(string const & name, bool allowUnsafe) const
656 EncodingList::const_iterator const it = encodinglist.find(name);
657 if (it == encodinglist.end())
659 if (!allowUnsafe && it->second.unsafe())
666 Encodings::fromLaTeXName(string const & n, int p, bool allowUnsafe) const
669 // FIXME: if we have to test for too many of these synonyms,
670 // we should instead extend the format of lib/encodings
674 // We don't use find_if because it makes copies of the pairs in
676 // This linear search is OK since we don't have many encodings.
677 // Users could even optimize it by putting the encodings they use
678 // most at the top of lib/encodings.
679 EncodingList::const_iterator const end = encodinglist.end();
680 for (EncodingList::const_iterator it = encodinglist.begin(); it != end; ++it)
681 if ((it->second.latexName() == name) && (it->second.package() & p)
682 && (!it->second.unsafe() || allowUnsafe))
689 Encodings::fromIconvName(string const & n, int p, bool allowUnsafe) const
691 EncodingList::const_iterator const end = encodinglist.end();
692 for (EncodingList::const_iterator it = encodinglist.begin(); it != end; ++it)
693 if ((it->second.iconvName() == n) && (it->second.package() & p)
694 && (!it->second.unsafe() || allowUnsafe))
700 Encodings::Encodings()
704 void Encodings::read(FileName const & encfile, FileName const & symbolsfile)
706 // We must read the symbolsfile first, because the Encoding
707 // constructor depends on it.
708 CharSetMap forcednotselected;
710 symbolslex.setFile(symbolsfile);
711 bool getNextToken = true;
712 while (symbolslex.isOK()) {
716 if (!symbolslex.next(true))
721 istringstream is(symbolslex.getString());
722 // reading symbol directly does not work if
723 // char_type == wchar_t.
725 if(!(is >> hex >> tmp))
729 if (!symbolslex.next(true))
731 docstring textcommand = symbolslex.getDocString();
732 if (!symbolslex.next(true))
734 string textpreamble = symbolslex.getString();
735 if (!symbolslex.next(true))
737 string sflags = symbolslex.getString();
742 if (suffixIs(textcommand, '}'))
743 flags |= CharInfoTextNoTermination;
744 while (!sflags.empty()) {
746 sflags = split(sflags, flag, ',');
747 if (flag == "combining") {
748 flags |= CharInfoCombining;
749 } else if (flag == "force") {
750 flags |= CharInfoForce;
751 forced.insert(symbol);
752 } else if (prefixIs(flag, "force=")) {
753 vector<string> encs =
754 getVectorFromString(flag.substr(6), ";");
755 for (auto const & enc : encs)
756 forcedselected[enc].insert(symbol);
757 flags |= CharInfoForceSelected;
758 } else if (prefixIs(flag, "force!=")) {
759 vector<string> encs =
760 getVectorFromString(flag.substr(7), ";");
761 for (auto const & enc : encs)
762 forcednotselected[enc].insert(symbol);
763 flags |= CharInfoForceSelected;
764 } else if (flag == "mathalpha") {
765 mathalpha.insert(symbol);
766 } else if (flag == "notermination=text") {
767 flags |= CharInfoTextNoTermination;
768 } else if (flag == "notermination=math") {
769 flags |= CharInfoMathNoTermination;
770 } else if (flag == "notermination=both") {
771 flags |= CharInfoTextNoTermination;
772 flags |= CharInfoMathNoTermination;
773 } else if (flag == "notermination=none") {
774 flags &= ~CharInfoTextNoTermination;
775 flags &= ~CharInfoMathNoTermination;
776 } else if (contains(flag, "tipaShortcut=")) {
777 tipashortcut = split(flag, '=');
778 } else if (flag == "deprecated") {
779 flags |= CharInfoDeprecated;
781 lyxerr << "Ignoring unknown flag `" << flag
782 << "' for symbol `0x"
783 << hex << symbol << dec
787 // mathCommand and mathPreamble have been added for 1.6.0.
788 // make them optional so that old files still work.
789 int const lineno = symbolslex.lineNumber();
790 bool breakout = false;
791 docstring mathcommand;
793 if (symbolslex.next(true)) {
794 if (symbolslex.lineNumber() != lineno) {
795 // line in old format without mathCommand and mathPreamble
796 getNextToken = false;
798 mathcommand = symbolslex.getDocString();
799 if (suffixIs(mathcommand, '}'))
800 flags |= CharInfoMathNoTermination;
801 if (symbolslex.next(true)) {
802 if (symbolslex.lineNumber() != lineno) {
803 // line in new format with mathCommand only
804 getNextToken = false;
806 // line in new format with mathCommand and mathPreamble
807 mathpreamble = symbolslex.getString();
816 // backward compatibility
817 if (mathpreamble == "esintoramsmath")
818 mathpreamble = "esint|amsmath";
820 if (!textpreamble.empty())
821 if (textpreamble[0] != '\\')
822 flags |= CharInfoTextFeature;
823 if (!mathpreamble.empty())
824 if (mathpreamble[0] != '\\')
825 flags |= CharInfoMathFeature;
827 CharInfo info = CharInfo(
828 textcommand, mathcommand,
829 textpreamble, mathpreamble,
830 tipashortcut, flags);
831 LYXERR(Debug::INFO, "Read unicode symbol " << symbol << " '"
832 << to_utf8(info.textCommand()) << "' '" << info.textPreamble()
833 << " '" << info.textFeature() << ' ' << info.textNoTermination()
834 << ' ' << to_utf8(info.mathCommand()) << "' '" << info.mathPreamble()
835 << "' " << info.mathFeature() << ' ' << info.mathNoTermination()
836 << ' ' << info.combining() << ' ' << info.force()
837 << ' ' << info.forceSelected());
839 // we assume that at least one command is nonempty when using unicodesymbols
840 if (info.isUnicodeSymbol()) {
841 unicodesymbols[symbol] = info;
848 // Now read the encodings
854 LexerKeyword encodingtags[] = {
855 { "encoding", et_encoding },
859 Lexer lex(encodingtags);
860 lex.setFile(encfile);
861 lex.setContext("Encodings::read");
867 string const name = lex.getString();
869 string const latexname = lex.getString();
871 string const guiname = lex.getString();
873 string const iconvname = lex.getString();
875 string const width = lex.getString();
876 bool fixedwidth = false;
878 if (width == "fixed")
880 else if (width == "variable")
882 else if (width == "variableunsafe") {
887 lex.printError("Unknown width");
890 string const p = lex.getString();
891 Encoding::Package package = Encoding::none;
893 package = Encoding::none;
894 else if (p == "inputenc")
895 package = Encoding::inputenc;
897 package = Encoding::CJK;
898 else if (p == "japanese")
899 package = Encoding::japanese;
901 lex.printError("Unknown package");
903 LYXERR(Debug::INFO, "Reading encoding " << name);
904 encodinglist[name] = Encoding(name, latexname,
905 guiname, iconvname, fixedwidth, unsafe,
908 if (lex.lex() != et_end)
909 lex.printError("Missing end");
913 lex.printError("Misplaced end");
915 case Lexer::LEX_FEOF:
918 lex.printError("Unknown tag");
923 // Move all information from forcednotselected to forcedselected
924 for (CharSetMap::const_iterator it1 = forcednotselected.begin(); it1 != forcednotselected.end(); ++it1) {
925 for (CharSetMap::iterator it2 = forcedselected.begin(); it2 != forcedselected.end(); ++it2) {
926 if (it2->first != it1->first)
927 it2->second.insert(it1->second.begin(), it1->second.end());