html_token.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2013 The ClanLib Team
4 **
5 ** This software is provided 'as-is', without any express or implied
6 ** warranty. In no event will the authors be held liable for any damages
7 ** arising from the use of this software.
8 **
9 ** Permission is granted to anyone to use this software for any purpose,
10 ** including commercial applications, and to alter it and redistribute it
11 ** freely, subject to the following restrictions:
12 **
13 ** 1. The origin of this software must not be misrepresented; you must not
14 ** claim that you wrote the original software. If you use this software
15 ** in a product, an acknowledgment in the product documentation would be
16 ** appreciated but is not required.
17 ** 2. Altered source versions must be plainly marked as such, and must not be
18 ** misrepresented as being the original software.
19 ** 3. This notice may not be removed or altered from any source distribution.
20 **
21 ** Note: Some of the libraries ClanLib may link to may have additional
22 ** requirements or restrictions.
23 **
24 ** File Author(s):
25 **
26 ** Magnus Norddahl
27 */
28 
29 #pragma once
30 
31 #include "../api_csslayout.h"
32 #include "../../Core/Text/string_help.h"
33 #include <string>
34 #include <vector>
35 
36 namespace clan
37 {
40 
41 class CL_API_CSSLAYOUT HTMLAttribute
42 {
43 public:
45  HTMLAttribute(const std::string &name, const std::string &value) : name(name), value(value) { }
46 
47  std::string name;
48  std::string value;
49 };
50 
51 class CL_API_CSSLAYOUT HTMLToken
52 {
53 public:
54  enum Type
55  {
65  type_invalid
66  };
67  HTMLToken() : type(type_null) { }
68  HTMLToken(Type type) : type(type) { }
69  HTMLToken(Type type, const std::string &name) : type(type), name(name) { }
70  HTMLToken(Type type, const std::string &name, const std::string &value) : type(type), name(name), value(value) { }
71  HTMLToken(Type type, const std::string &name, const std::string &value, const std::vector<HTMLAttribute> &attributes) : type(type), name(name), value(value), attributes(attributes) { }
72 
74  std::string name;
75  std::string value;
76  std::vector<HTMLAttribute> attributes;
77 
78  bool has_attribute(const std::string &name) const
79  {
80  for (size_t i = 0; i < attributes.size(); i++)
81  if (StringHelp::compare(attributes[i].name, name, true) == 0)
82  return true;
83  return false;
84  }
85 
86  std::string get_attribute(const std::string &name) const
87  {
88  for (size_t i = 0; i < attributes.size(); i++)
89  if (StringHelp::compare(attributes[i].name, name, true) == 0)
90  return attributes[i].value;
91  return std::string();
92  }
93 };
94 
96 }
HTMLToken()
Definition: html_token.h:67
HTMLToken(Type type, const std::string &name, const std::string &value)
Definition: html_token.h:70
Definition: html_token.h:59
Type
Definition: html_token.h:54
Definition: html_token.h:41
std::string get_attribute(const std::string &name) const
Definition: html_token.h:86
std::string value
Definition: html_token.h:75
HTMLToken(Type type, const std::string &name)
Definition: html_token.h:69
HTMLToken(Type type, const std::string &name, const std::string &value, const std::vector< HTMLAttribute > &attributes)
Definition: html_token.h:71
Definition: html_token.h:56
Definition: html_token.h:60
static int compare(const std::string &a, const std::string &b, bool case_insensitive=false)
Compare.
Definition: html_token.h:64
Definition: html_token.h:58
Definition: html_token.h:51
HTMLAttribute()
Definition: html_token.h:44
HTMLToken(Type type)
Definition: html_token.h:68
Definition: html_token.h:61
std::string name
Definition: html_token.h:74
std::string name
Definition: html_token.h:47
std::vector< HTMLAttribute > attributes
Definition: html_token.h:76
std::string value
Definition: html_token.h:48
Definition: html_token.h:63
Definition: html_token.h:57
Definition: html_token.h:62
HTMLAttribute(const std::string &name, const std::string &value)
Definition: html_token.h:45
Type type
Definition: html_token.h:73
bool has_attribute(const std::string &name) const
Definition: html_token.h:78