uri_template.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * \copyright Copyright 2013 Google Inc. All Rights Reserved.
  3. * \license @{
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. * @}
  18. */
  19. #ifndef NET_THIRD_PARTY_URI_TEMPLATE_URI_TEMPLATE_H_
  20. #define NET_THIRD_PARTY_URI_TEMPLATE_URI_TEMPLATE_H_
  21. #include <set>
  22. #include <string>
  23. #include <unordered_map>
  24. #include "base/component_export.h"
  25. using std::string;
  26. namespace uri_template {
  27. /*
  28. * Produce concrete URLs from templated ones. Collect the names of any expanded
  29. * variables. Supports templates up to level 3 as specified in RFC 6570 with
  30. * some limitations: it does not check for disallowed characters in variable
  31. * names, and it does not do any encoding during literal expansion.
  32. *
  33. * @param[in] uri The templated uri to expand.
  34. * @param[in] parameters A map containing variables and corresponding values.
  35. * @param[out] target The string to resolve the templated uri into.
  36. * @param[out] vars_found Populated with the list of variables names
  37. * that were resolved while expanding the uri. NULL is permitted
  38. * if the caller does not wish to collect these.
  39. *
  40. * @return true if the template was parseable. false if it was malformed.
  41. */
  42. COMPONENT_EXPORT(URI_TEMPLATE)
  43. bool Expand(const string& template_uri,
  44. const std::unordered_map<string, string>& parameters,
  45. string* target,
  46. std::set<string>* vars_found = nullptr);
  47. } // namespace uri_template
  48. #endif // NET_THIRD_PARTY_URI_TEMPLATE_URI_TEMPLATE_H_