X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fceph%2Fsrc%2Fdmclock%2Fsim%2Fsrc%2Fstr_list.cc;fp=src%2Fceph%2Fsrc%2Fdmclock%2Fsim%2Fsrc%2Fstr_list.cc;h=22109e00840482bf475e472640281fd1f724dec6;hb=812ff6ca9fcd3e629e49d4328905f33eee8ca3f5;hp=0000000000000000000000000000000000000000;hpb=15280273faafb77777eab341909a3f495cf248d9;p=stor4nfv.git diff --git a/src/ceph/src/dmclock/sim/src/str_list.cc b/src/ceph/src/dmclock/sim/src/str_list.cc new file mode 100644 index 0000000..22109e0 --- /dev/null +++ b/src/ceph/src/dmclock/sim/src/str_list.cc @@ -0,0 +1,106 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2009-2010 Dreamhost + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + * + */ + +#include "str_list.h" + +using std::string; +using std::vector; +using std::set; +using std::list; + +static bool get_next_token(const string &s, size_t& pos, const char *delims, string& token) +{ + int start = s.find_first_not_of(delims, pos); + int end; + + if (start < 0){ + pos = s.size(); + return false; + } + + end = s.find_first_of(delims, start); + if (end >= 0) + pos = end + 1; + else { + pos = end = s.size(); + } + + token = s.substr(start, end - start); + return true; +} + +void get_str_list(const string& str, const char *delims, list& str_list) +{ + size_t pos = 0; + string token; + + str_list.clear(); + + while (pos < str.size()) { + if (get_next_token(str, pos, delims, token)) { + if (token.size() > 0) { + str_list.push_back(token); + } + } + } +} + +void get_str_list(const string& str, list& str_list) +{ + const char *delims = ";,= \t"; + return get_str_list(str, delims, str_list); +} + +void get_str_vec(const string& str, const char *delims, vector& str_vec) +{ + size_t pos = 0; + string token; + str_vec.clear(); + + while (pos < str.size()) { + if (get_next_token(str, pos, delims, token)) { + if (token.size() > 0) { + str_vec.push_back(token); + } + } + } +} + +void get_str_vec(const string& str, vector& str_vec) +{ + const char *delims = ";,= \t"; + return get_str_vec(str, delims, str_vec); +} + +void get_str_set(const string& str, const char *delims, set& str_set) +{ + size_t pos = 0; + string token; + + str_set.clear(); + + while (pos < str.size()) { + if (get_next_token(str, pos, delims, token)) { + if (token.size() > 0) { + str_set.insert(token); + } + } + } +} + +void get_str_set(const string& str, set& str_set) +{ + const char *delims = ";,= \t"; + return get_str_set(str, delims, str_set); +}