utils.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Tencent is pleased to support the open source community by making wwsearch
  3. * available.
  4. *
  5. * Copyright (C) 2018-present Tencent. All Rights Reserved.
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  8. * use this file except in compliance with the License. You may obtain a copy of
  9. * the License at
  10. *
  11. * https://opensource.org/licenses/Apache-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. * WARRANTIES OF ANY KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations under the License.
  17. */
  18. #pragma once
  19. #include <iterator>
  20. #include <sstream>
  21. #include <string>
  22. #include <vector>
  23. namespace wwsearch {
  24. class Codec;
  25. std::string DebugInvertedValue(const std::string& value);
  26. std::string DebugInvertedValueByReader(Codec* codec, const std::string& value);
  27. void SplitString(const std::string& full, const std::string& delim,
  28. std::vector<std::string>* result);
  29. std::string TrimString(const std::string& str, const std::string& trim = " ");
  30. template <class Container>
  31. std::string JoinContainerToString(const Container& c,
  32. const std::string& joiner) {
  33. std::string result;
  34. if (!c.empty()) {
  35. std::ostringstream ss;
  36. std::copy(c.begin(), c.end(),
  37. std::ostream_iterator<typename Container::value_type>(
  38. ss, joiner.c_str()));
  39. result = ss.str();
  40. result.erase(result.length() - 1);
  41. }
  42. return result;
  43. }
  44. } // namespace wwsearch