classify.cc 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright (C) 2014, 2015 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #include <config.h>
  15. #include <dhcp/classify.h>
  16. #include <util/strutil.h>
  17. #include <boost/algorithm/string/classification.hpp>
  18. #include <boost/algorithm/string/constants.hpp>
  19. #include <boost/algorithm/string/split.hpp>
  20. #include <vector>
  21. namespace isc {
  22. namespace dhcp {
  23. ClientClasses::ClientClasses(const std::string& class_names)
  24. : std::set<ClientClass>() {
  25. std::vector<std::string> split_text;
  26. boost::split(split_text, class_names, boost::is_any_of(","),
  27. boost::algorithm::token_compress_off);
  28. for (size_t i = 0; i < split_text.size(); ++i) {
  29. std::string trimmed = util::str::trim(split_text[i]);
  30. // Ignore empty class names.
  31. if (!trimmed.empty()) {
  32. insert(ClientClass(trimmed));
  33. }
  34. }
  35. }
  36. } // end of namespace isc::dhcp
  37. } // end of namespace isc