X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fsvec.c;h=d576c21d1e29addd55c4d565fc35eb982b112150;hb=4e6ca956f56b7a7f7284a4cd8788873ba57b229c;hp=078b107042195900bf35da392cefd48b35161f07;hpb=34e63086edddcae06d7c1a4fa84fec0861e50758;p=openvswitch diff --git a/lib/svec.c b/lib/svec.c index 078b1070..d576c21d 100644 --- a/lib/svec.c +++ b/lib/svec.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2009 Nicira Networks. + * Copyright (c) 2008, 2009, 2010 Nicira Networks. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,10 +22,10 @@ #include #include "dynamic-string.h" #include "util.h" - -#define THIS_MODULE VLM_svec #include "vlog.h" +VLOG_DEFINE_THIS_MODULE(svec); + void svec_init(struct svec *svec) { @@ -49,7 +49,7 @@ svec_destroy(struct svec *svec) } void -svec_clear(struct svec *svec) +svec_clear(struct svec *svec) { size_t i; @@ -59,6 +59,12 @@ svec_clear(struct svec *svec) svec->n = 0; } +bool +svec_is_empty(const struct svec *svec) +{ + return svec->n == 0; +} + void svec_add(struct svec *svec, const char *name) { @@ -366,6 +372,22 @@ svec_join(const struct svec *svec, return ds_cstr(&ds); } +/* Breaks 's' into tokens at any character in 'delimiters', and appends each + * token to 'svec'. Empty tokens are not added. */ +void +svec_split(struct svec *svec, const char *s_, const char *delimiters) +{ + char *s = xstrdup(s_); + char *save_ptr = NULL; + char *token; + + for (token = strtok_r(s, delimiters, &save_ptr); token != NULL; + token = strtok_r(NULL, delimiters, &save_ptr)) { + svec_add(svec, token); + } + free(s); +} + const char * svec_back(const struct svec *svec) {