X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=classes%2Fplflagset.php;h=c6c8d41f93b123407edf5a4545f95c60c2c6d9fc;hb=5f6b3a28efe41c038f349fb0b281d9637f7078de;hp=1971751ce368fe3d31b6187713abd3dd02fb0f92;hpb=ba63661ce2f38974002c7e4113320e9d06010853;p=platal.git diff --git a/classes/plflagset.php b/classes/plflagset.php index 1971751..c6c8d41 100644 --- a/classes/plflagset.php +++ b/classes/plflagset.php @@ -1,6 +1,6 @@ sep = $sep; $splitted = explode($sep, $flags); foreach ($splitted as $part) { - $this->values[$part] = true; + if (!empty($part)) { + $this->values[$part] = true; + } } } /** add flag - * @param $flag XXX + * @param $flag name of the flag + * @param $cond if true, add the flag (default is true), else, ignore. * @return VOID */ - public function addFlag($flag) + public function addFlag($flag, $cond = true) { - if (empty($flag)) { + if (empty($flag) || !$cond) { return; } $this->values[$flag] = true; @@ -101,6 +104,13 @@ class PlFlagSet } } + /** Remove all the flags. + */ + public function clear() + { + $this->values = array(); + } + /** return the PlFlagSet */ @@ -117,6 +127,34 @@ class PlFlagSet } return $flags; } + + /** export the PlFlagSet + */ + public function export() + { + $array = array(); + foreach ($this->values as $key=>$value) { + if ($value) { + $array[] = $key; + } + } + return $array; + } + + /** format for XDB + */ + public function format() + { + return XDB::escape($this->flags()); + } + + + /** Build an iterator for this PlFlagSet. + */ + public function iterate() + { + return PlIteratorUtils::fromArray($this->export(), 1, true); + } } // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: