Skip to content

Commit

Permalink
Include missing file.
Browse files Browse the repository at this point in the history
  • Loading branch information
kohler committed Nov 1, 2023
1 parent abec2d1 commit 7b02b9c
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions batch/makedist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ src/documentinfo.php
src/documentinfoset.php
src/documenthashmatcher.php
src/documentrequest.php
src/fieldchangeset.php
src/fieldrender.php
src/filefilter.php
src/formatspec.php
Expand Down
55 changes: 55 additions & 0 deletions src/fieldchangeset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
// fieldchangeset.php -- HotCRP helper for `status:unchanged`/`status:changed`
// Copyright (c) 2023 Eddie Kohler; see LICENSE.

class FieldChangeSet {
/** @var array<string,1|2|3> */
public $_m = [];

const ABSENT = 0;
const UNCHANGED = 1;
const CHANGED = 2;

/** @param ?string $s
* @return $this */
function mark_unchanged($s) {
$this->apply($s, self::UNCHANGED);
return $this;
}

/** @param ?string $s
* @return $this */
function mark_changed($s) {
$this->apply($s, self::CHANGED);
return $this;
}

/** @param string $src
* @param string $dst
* @return $this */
function mark_synonym($src, $dst) {
$this->_m[$src] = $this->_m[$dst] =
($this->_m[$src] ?? 0) | ($this->_m[$dst] ?? 0);
return $this;
}

/** @param ?string $s
* @param 1|2 $bit */
private function apply($s, $bit) {
foreach (explode(" ", $s ?? "") as $word) {
if ($word !== "") {
$this->_m[$word] = ($this->_m[$word] ?? 0) | $bit;
if (($colon = strpos($word, ":")) !== false) {
$px = substr($word, 0, $colon);
$this->_m[$px] = ($this->_m[$px] ?? 0) | $bit;
}
}
}
}

/** @param string $key
* @return 0|1|2|3 */
function test($key) {
return $this->_m[$key] ?? 0;
}
}

0 comments on commit 7b02b9c

Please sign in to comment.