| 181 | } |
| 182 | |
| 183 | bool |
| 184 | AttributeParser::parse(const char c) |
| 185 | { |
| 186 | switch (state_) { |
| 187 | case Attribute::kPreName: |
| 188 | if (isValidName(c)) { |
| 189 | state_ = Attribute::kName; |
| 190 | attributes.push_back(Pair()); |
| 191 | attributes.back().first += c; |
| 192 | } else if (c == '/' || c == '>') { |
| 193 | return true; |
| 194 | } |
| 195 | break; |
| 196 | case Attribute::kName: |
| 197 | if (isValidName(c)) { |
| 198 | attributes.back().first += c; |
| 199 | } else if (c == '=') { |
| 200 | state_ = Attribute::kPreValue; |
| 201 | } else if (c == '/' || c == '>') { |
| 202 | return true; |
| 203 | } else { |
| 204 | state_ = Attribute::kPostName; |
| 205 | } |
| 206 | break; |
| 207 | case Attribute::kPostName: |
| 208 | if (isValidName(c)) { |
| 209 | state_ = Attribute::kName; |
| 210 | attributes.push_back(Pair()); |
| 211 | attributes.back().first += c; |
| 212 | } else if (c == '=') { |
| 213 | state_ = Attribute::kPreValue; |
| 214 | } else if (c == '/' || c == '>') { |
| 215 | return true; |
| 216 | } |
| 217 | break; |
| 218 | case Attribute::kPreValue: |
| 219 | // TODO(dmorilha) add the unquoted value. |
| 220 | if (c == '\'') { |
| 221 | state_ = Attribute::kSingleQuotedValue; |
| 222 | } else if (c == '"') { |
| 223 | state_ = Attribute::kDoubleQuotedValue; |
| 224 | // VERY BROKEN SYNTAX |
| 225 | } else if (c == '/' || c == '>') { |
| 226 | return true; |
| 227 | } else if (isValidValue(c)) { |
| 228 | state_ = Attribute::kUnquotedValue; |
| 229 | attributes.back().second += c; |
| 230 | } |
| 231 | break; |
| 232 | case Attribute::kUnquotedValue: |
| 233 | if (isValidValue(c)) { |
| 234 | attributes.back().second += c; |
| 235 | } else if (c == '/' || c == '>' || c == '"' || c == '\'') { |
| 236 | return true; |
| 237 | // space? |
| 238 | } else { |
| 239 | state_ = Attribute::kPreName; |
| 240 | } |