utils.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Copyright 2019 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #pragma once
  17. #include <string>
  18. #include <unordered_map>
  19. namespace android {
  20. namespace bluetooth {
  21. namespace audio {
  22. namespace utils {
  23. // Creates a hash map based on the |params| string containing key and value
  24. // pairs. Pairs are expected in the form "key=value" separated by the ';'
  25. // character. Both ';' and '=' characters are invalid in keys or values.
  26. // Examples:
  27. // "key0" -> map: [key0]=""
  28. // "key0=value0;key1=value1;" -> map: [key0]="value0" [key1]="value1"
  29. // "key0=;key1=value1;" -> map: [key0]="" [key1]="value1"
  30. // "=value0;key1=value1;" -> map: [key1]="value1"
  31. std::unordered_map<std::string, std::string> ParseAudioParams(
  32. const std::string& params);
  33. // Dumps the contents of the hash_map to the log for debugging purposes.
  34. // If |map| is not NULL, all entries of |map| will be dumped, otherwise
  35. // nothing will be dumped. Note that this function does not take the ownership
  36. // of the |map|.
  37. std::string GetAudioParamString(
  38. std::unordered_map<std::string, std::string>& params_map);
  39. } // namespace utils
  40. } // namespace audio
  41. } // namespace bluetooth
  42. } // namespace android