| 719 | } |
| 720 | |
| 721 | cm::optional<std::vector<std::string>> cmWindowsRegistry::ExpandExpression( |
| 722 | cm::string_view expression, View view, cm::string_view separator) |
| 723 | { |
| 724 | #if defined(_WIN32) && !defined(__CYGWIN__) |
| 725 | static std::string NOTFOUND{ "/REGISTRY-NOTFOUND" }; |
| 726 | |
| 727 | this->LastError.clear(); |
| 728 | |
| 729 | // compute list of registry views |
| 730 | auto views = this->ComputeViews(view); |
| 731 | std::vector<std::string> result; |
| 732 | |
| 733 | for (auto v : views) { |
| 734 | ExpressionParser parser(expression); |
| 735 | |
| 736 | while (parser.Find()) { |
| 737 | try { |
| 738 | auto handler = |
| 739 | KeyHandler::OpenKey(parser.GetRootKey(), parser.GetSubKey(), v); |
| 740 | auto data = handler.ReadValue(parser.GetValueName(), |
| 741 | this->SupportedTypes, separator); |
| 742 | parser.Replace(data); |
| 743 | } catch (registry_error const& e) { |
| 744 | this->LastError = e.what(); |
| 745 | parser.Replace(NOTFOUND); |
| 746 | continue; |
| 747 | } |
| 748 | } |
| 749 | result.emplace_back(parser.GetExpression()); |
| 750 | if (expression == parser.GetExpression()) { |
| 751 | // there no substitutions, so can ignore other views |
| 752 | break; |
| 753 | } |
| 754 | } |
| 755 | |
| 756 | return result; |
| 757 | #else |
| 758 | (void)view; |
| 759 | (void)separator; |
| 760 | |
| 761 | ExpressionParser parser(expression); |
| 762 | if (parser.Find()) { |
| 763 | // expression holds unsupported registry access |
| 764 | // so the expression cannot be used on this platform |
| 765 | return cm::nullopt; |
| 766 | } |
| 767 | return std::vector<std::string>{ std::string{ expression } }; |
| 768 | #endif |
| 769 | } |
no test coverage detected