hash_map_utils.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /******************************************************************************
  2. *
  3. * Copyright 2015 Google, Inc.
  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. #pragma once
  19. #include <string>
  20. #include <unordered_map>
  21. // Creates a hash map based on the |params| string containing key and value
  22. // pairs. Pairs are expected in the form "key=value" separated by the ';'
  23. // character. Both ';' and '=' characters are invalid in keys or values.
  24. // |params| cannot be NULL, is not modified and is owned by the caller.
  25. // Examples:
  26. // "key0=value10;key1=value1;" -> map: [key0]="value0" [key1]="value1"
  27. // "key0=;key1=value1;" -> map: [key0]="" [key1]="value1"
  28. // "=value0;key1=value1;" -> map: [key1]="value1"
  29. // A new hash map or NULL is returned and is owned by the caller.
  30. std::unordered_map<std::string, std::string>
  31. hash_map_utils_new_from_string_params(const char* params);
  32. // Dumps the contents of the hash_map to the log for debugging purposes.
  33. // If |map| is not NULL, all entries of |map| will be dumped, otherwise nothing
  34. // will be dumped. Note that this function does not take the ownership of |map|.
  35. void hash_map_utils_dump_string_keys_string_values(
  36. std::unordered_map<std::string, std::string>& map);