classify.cc 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright (C) 2014-2016 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this
  5. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
  6. #include <config.h>
  7. #include <dhcp/classify.h>
  8. #include <util/strutil.h>
  9. #include <boost/algorithm/string/classification.hpp>
  10. #include <boost/algorithm/string/constants.hpp>
  11. #include <boost/algorithm/string/split.hpp>
  12. #include <sstream>
  13. #include <vector>
  14. namespace isc {
  15. namespace dhcp {
  16. ClientClasses::ClientClasses(const std::string& class_names)
  17. : std::set<ClientClass>() {
  18. std::vector<std::string> split_text;
  19. boost::split(split_text, class_names, boost::is_any_of(","),
  20. boost::algorithm::token_compress_off);
  21. for (size_t i = 0; i < split_text.size(); ++i) {
  22. std::string trimmed = util::str::trim(split_text[i]);
  23. // Ignore empty class names.
  24. if (!trimmed.empty()) {
  25. insert(ClientClass(trimmed));
  26. }
  27. }
  28. }
  29. std::string
  30. ClientClasses::toText(const std::string& separator) const {
  31. std::stringstream s;
  32. for (const_iterator class_it = begin(); class_it != end(); ++class_it) {
  33. if (class_it != begin()) {
  34. s << separator;
  35. }
  36. s << *class_it;
  37. }
  38. return (s.str());
  39. }
  40. } // end of namespace isc::dhcp
  41. } // end of namespace isc