+ void parseAsLegacy() {
+ // Determine if some features are known not to be supported. For now, this is only formatting like
+ // \index{alpha@\textbf{alpha}} or \index{alpha@$\alpha$}.
+ // @ is supported, but only for sorting, without specific formatting.
+ if (entry_.find(from_utf8("@\\")) != lyx::docstring::npos) {
+ output_error_ += from_utf8("Unsupported feature: an index entry contains an @\\. "
+ "Complete entry: \"") + entry_ + from_utf8("\". ");
+ }
+ if (entry_.find(from_utf8("@$")) != lyx::docstring::npos) {
+ output_error_ += from_utf8("Unsupported feature: an index entry contains an @$. "
+ "Complete entry: \"") + entry_ + from_utf8("\". ");
+ }
+
+ // Split the string into its main constituents: terms, and command (see, see also, range).
+ size_t positionVerticalBar = entry_.find(from_ascii("|")); // What comes before | is (sub)(sub)entries.
+ docstring indexTerms = entry_.substr(0, positionVerticalBar);
+ docstring command;
+ if (positionVerticalBar != lyx::docstring::npos) {
+ command = entry_.substr(positionVerticalBar + 1);
+ }
+
+ // Handle sorting issues, with @.
+ vector<docstring> sortingElements = getVectorFromString(indexTerms, from_ascii("@"), false);
+ if (sortingElements.size() == 2) {
+ sort_as_ = sortingElements[0];
+ indexTerms = sortingElements[1];
+ }
+
+ // Handle entries, subentries, and subsubentries.
+ terms_ = getVectorFromString(indexTerms, from_ascii("!"), false);
+
+ // Handle ranges. Happily, (| and |) can only be at the end of the string!
+ has_start_range_ = entry_.find(from_ascii("|(")) != lyx::docstring::npos;
+ has_end_range_ = entry_.find(from_ascii("|)")) != lyx::docstring::npos;
+
+ // - Remove the ranges from the command if they do not appear at the beginning.
+ size_t range_index = 0;
+ while ((range_index = command.find(from_utf8("|("), range_index)) != std::string::npos)
+ command.erase(range_index, 1);
+ range_index = 0;
+ while ((range_index = command.find(from_utf8("|)"), range_index)) != std::string::npos)
+ command.erase(range_index, 1);
+
+ // - Remove the ranges when they are the only vertical bar in the complete string.
+ if (command[0] == '(' || command[0] == ')')
+ command.erase(0, 1);
+
+ // Handle see and seealso. As "see" is a prefix of "seealso", the order of the comparisons is important.
+ // Both commands are mutually exclusive!
+ if (command.substr(0, 3) == "see") {
+ // Unescape brackets.
+ size_t index_argument_begin = 0;
+ while ((index_argument_begin = command.find(from_utf8("\\{"), index_argument_begin)) != std::string::npos)
+ command.erase(index_argument_begin, 1);
+ size_t index_argument_end = 0;
+ while ((index_argument_end = command.find(from_utf8("\\}"), index_argument_end)) != std::string::npos)
+ command.erase(index_argument_end, 1);
+
+ // Retrieve the part between brackets, and remove the complete seealso.
+ size_t position_opening_bracket = command.find(from_ascii("{"));
+ size_t position_closing_bracket = command.find(from_ascii("}"));
+ docstring argument = command.substr(position_opening_bracket + 1,
+ position_closing_bracket - position_opening_bracket - 1);
+
+ // Parse the argument of referenced entries (or a single one for see).
+ if (command.substr(0, 7) == "seealso") {
+ see_alsoes_ = getVectorFromString(argument, from_ascii(","), false);
+ } else {
+ see_ = argument;
+
+ if (see_.find(from_ascii(",")) != std::string::npos) {
+ output_error_ += from_utf8("Several index_argument_end terms found as \"see\"! Only one is "
+ "acceptable. Complete entry: \"") + entry_ + from_utf8("\". ");
+ }
+ }
+
+ // Remove the complete see/seealso from the commands, in case there is something else to parse.
+ command = command.substr(position_closing_bracket + 1);
+ }
+
+ // Some parts of the strings are not parsed, as they do not have anything matching in DocBook or XHTML:
+ // things like formatting the entry or the page number, other strings for sorting.
+ // https://wiki.lyx.org/Tips/Indexing
+ // If there are such things in the index entry, then this code may miserably fail. For example, for
+ // "Peter|(textbf", no range will be detected.
+ if (!command.empty()) {
+ output_error_ += from_utf8("Unsupported feature: an index entry contains a | with an unsupported command, ")
+ + command + from_utf8(". Complete entry: \"") + entry_ + from_utf8("\". ");
+ }