X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=classes%2Fplflagset.php;fp=classes%2Fflagset.php;h=1971751ce368fe3d31b6187713abd3dd02fb0f92;hb=113f6de8c1546c1d1caf6e6b48f5e10ea85fd211;hp=3e723308f6107723365040d516798e6be7ac4501;hpb=4a28e567307ee8061d96f631547fe24c68f0f5eb;p=platal.git diff --git a/classes/flagset.php b/classes/plflagset.php similarity index 69% rename from classes/flagset.php rename to classes/plflagset.php index 3e72330..1971751 100644 --- a/classes/flagset.php +++ b/classes/plflagset.php @@ -21,22 +21,26 @@ /** class for describing flags */ -class Flagset +class PlFlagSet { - /** string that holds the flagset */ - private $value; + /** string that holds the PlFlagSet */ + private $values = array(); /** the boundary between flags */ - private $sep = ","; + private $sep; /** set flag * @param $flags services FROM coupures * @return VOID */ - public function __construct($flags = "") + public function __construct($flags = '', $sep = ',') { - $this->value = $flags; + $this->sep = $sep; + $splitted = explode($sep, $flags); + foreach ($splitted as $part) { + $this->values[$part] = true; + } } @@ -46,12 +50,10 @@ class Flagset */ public function addFlag($flag) { - if (!$flag) return; - if (!$this->hasflag($flag)) { - if ($this->value) - $this->value .= $this->sep; - $this->value .= $flag; + if (empty($flag)) { + return; } + $this->values[$flag] = true; } @@ -61,12 +63,7 @@ class Flagset */ public function hasFlag($flag) { - $tok = strtok($this->value,$this->sep); - while ($tok) { - if ($tok==$flag) return 1; - $tok = strtok($this->sep); - } - return 0; + return !empty($flag) && isset($this->values[$flag]) && $this->values[$flag]; } /** test flag combination @@ -96,25 +93,29 @@ class Flagset */ public function rmFlag($flag) { - if (!$flag) return; - $newvalue = ""; - $tok = strtok($this->value,$this->sep); - while ($tok) { - if ($tok!=$flag) { - if ($newvalue) - $newvalue .= $this->sep; - $newvalue .= $tok; - } - $tok = strtok($this->sep); + if (empty($flag)) { + return; + } + if (isset($this->values[$flag])) { + unset($this->values[$flag]); } - $this->value=$newvalue; } - /** return the flagset + + /** return the PlFlagSet */ public function flags() { - return $this->value; + $flags = ''; + foreach ($this->values as $key=>$value) { + if (!empty($flags)) { + $flags .= $this->sep; + } + if ($value) { + $flags .= $key; + } + } + return $flags; } }