changed: update version strings for beta4
[xbmc.git] / xbmc / utils / HTMLTable.cpp
blobe9735e7f548c75a069c9710add730bc8dff0e561
1 /*
2 * Copyright (C) 2005-2008 Team XBMC
3 * http://www.xbmc.org
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)
8 * any later version.
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"
23 #include "HTMLUtil.h"
26 using namespace HTML;
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)
46 CHTMLUtil util;
47 CStdString strTag;
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)
57 break;
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());
88 CHTMLUtil util;
89 CStdString strTag;
90 int iPosStart = util.FindTag(strHTML, "<table", strTag);
91 if (iPosStart >= 0)
93 iPosStart += (int)strTag.size();
94 int iPosEnd = util.FindClosingTag(strHTML, "table", strTag, iPosStart) - 1;
95 if (iPosEnd < 0)
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)
110 break;
112 CStdString strRow = strTable.Mid(iTableRowStart, 1 + iTableRowEnd - iTableRowStart);
113 CHTMLRow row;
114 row.Parse(strRow);
115 m_vecRows.push_back(row);
116 iTableRowStart = iTableRowEnd + 1;
119 while (iTableRowStart >= 0);