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