1: <?php
2: /*
3: * Copyright (c) 2016 Geraldo B. Landre
4: *
5: * See the file LICENSE for copying permission.
6: */
7: namespace pgn\tags;
8:
9: use utils\Parser;
10:
11: /**
12: * Description of White:
13: * The White tag value is the name of the player or players of the white pieces.
14: * The names are given as they would appear in a telephone directory. The family
15: * or last name appears first. If a first name or first initial is available, it
16: * is separated from the family name by a comma and a space. Finally, one or more
17: * middle initials may appear. (Wherever a comma appears, the very next character
18: * should be a space. Wherever an initial appears, the very next character should
19: * be a period.) If the name is unknown, a single question mark should appear as
20: * the tag value.
21: *
22: * The intent is to allow meaningful ASCII sorting of the tag value that is
23: * independent of regional name formation customs. If more than one person is
24: * playing the white pieces, the names are listed in alphabetical order and are
25: * separated by the colon character between adjacent entries. A player who is
26: * also a computer program should have appropriate version information listed
27: * after the name of the program.
28: *
29: * The format used in the FIDE Rating Lists is appropriate for use for player name
30: * tags.
31: *
32: * Examples:
33: *
34: * [White "Tal, Mikhail N."]
35: *
36: * [White "van der Wiel, Johan"]
37: *
38: * [White "Acme Pawngrabber v.3.2"]
39: *
40: * @see pgn_standard.txt
41: * @author Geraldo
42: */
43: class White extends Tag {
44:
45: /**
46: * @assert () === 'White'
47: * @return string White
48: */
49: public function getName() {
50: $parsed = Parser::parseClassName(get_class());
51: return $parsed['className'];
52: }
53:
54: /**
55: * Validation rules:
56: * "...(Wherever a comma appears, the very next character
57: * should be a space..."
58: * Tests based on description:
59: * @assert("Tal, Mikhail N.") === true
60: * @assert("van der Wiel, Johan") === true
61: * @assert("Acme Pawngrabber v.3.2") === true
62: * @assert("?") === true
63: * Basic path tests:
64: * @assert (NULL) === false
65: * @assert ("ab") === true
66: * @assert (", ") === true
67: * @assert (",a") === false
68: * @assert ("a") === true
69: * @param string $data
70: * @return bool true if data is valid and false if not.
71: */
72: public function validate($data) {
73: if (!parent::validate($data)) {
74: return false;
75: }
76:
77: while (strlen($data) >= 2) {
78: if ($data[0] == ',' && $data[1] != ' ') {
79: return false;
80: }
81:
82: $previousLength = strlen($data);
83: $data = strstr($data, ',');
84:
85: if(strlen($data) == $previousLength) {
86: return true;
87: }
88: }
89:
90: return true;
91: }
92:
93: }
94: