2 * Copyright (C) 2005-2008 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, write to
17 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 * http://www.gnu.org/copyleft/gpl.html
22 #include "HTMLTable.h"
28 CHTMLRow::CHTMLRow(void)
31 CHTMLRow::~CHTMLRow(void)
34 int CHTMLRow::GetColumns() const
36 return (int)m_vecColums
.size();
39 const CStdString
& CHTMLRow::GetColumValue(int iColumn
) const
41 return m_vecColums
[iColumn
];
44 void CHTMLRow::Parse(const CStdString
& strTable
)
48 int iTableRowStart
= 0;
51 iTableRowStart
= util
.FindTag(strTable
, "<td", strTag
, iTableRowStart
);
52 if (iTableRowStart
>= 0)
54 iTableRowStart
+= (int)strTag
.size();
55 int iTableRowEnd
= util
.FindClosingTag(strTable
, "td", strTag
, iTableRowStart
) - 1;
56 if (iTableRowEnd
< -1)
59 CStdString strRow
= strTable
.Mid(iTableRowStart
, 1 + iTableRowEnd
- iTableRowStart
);
60 m_vecColums
.push_back(strRow
);
62 iTableRowStart
= iTableRowEnd
+ 1;
66 while (iTableRowStart
>= 0);
68 //------------------------------------------------------------------------------
69 CHTMLTable::CHTMLTable(void)
72 CHTMLTable::~CHTMLTable(void)
75 int CHTMLTable::GetRows() const
77 return (int)m_vecRows
.size();
80 const CHTMLRow
& CHTMLTable::GetRow(int iRow
) const
82 return m_vecRows
[iRow
];
85 void CHTMLTable::Parse(const CStdString
& strHTML
)
87 m_vecRows
.erase(m_vecRows
.begin(), m_vecRows
.end());
90 int iPosStart
= util
.FindTag(strHTML
, "<table", strTag
);
93 iPosStart
+= (int)strTag
.size();
94 int iPosEnd
= util
.FindClosingTag(strHTML
, "table", strTag
, iPosStart
) - 1;
97 iPosEnd
= (int)strHTML
.size();
100 CStdString strTable
= strHTML
.Mid(iPosStart
, 1 + iPosEnd
- iPosStart
);
101 int iTableRowStart
= 0;
104 iTableRowStart
= util
.FindTag(strTable
, "<tr", strTag
, iTableRowStart
);
105 if (iTableRowStart
>= 0)
107 iTableRowStart
+= (int)strTag
.size();
108 int iTableRowEnd
= util
.FindClosingTag(strTable
, "tr", strTag
, iTableRowStart
) - 1;
109 if (iTableRowEnd
< 0)
112 CStdString strRow
= strTable
.Mid(iTableRowStart
, 1 + iTableRowEnd
- iTableRowStart
);
115 m_vecRows
.push_back(row
);
116 iTableRowStart
= iTableRowEnd
+ 1;
119 while (iTableRowStart
>= 0);