3 * Class used to parse tables received from director in this format :
5 * +---------+---------+-------------------+
6 * | Header1 | Header2 | ... |
7 * +---------+---------+-------------------+
8 * | Data11 | Data12 | ... |
10 * +---------+---------+-------------------+
12 * Nicolas Boichat, April 2004
17 Copyright (C) 2004 Kern Sibbald and John Walker
19 This program is free software; you can redistribute it and/or
20 modify it under the terms of the GNU General Public License
21 as published by the Free Software Foundation; either version 2
22 of the License, or (at your option) any later version.
24 This program is distributed in the hope that it will be useful,
25 but WITHOUT ANY WARRANTY; without even the implied warranty of
26 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 GNU General Public License for more details.
29 You should have received a copy of the GNU General Public License
30 along with this program; if not, write to the Free Software
31 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 #include "wxbtableparser.h" // class's header file
38 #include <wx/tokenzr.h>
40 #include "wxbmainframe.h"
42 #include <wx/arrimpl.cpp>
44 WX_DEFINE_OBJARRAY(wxbTable);
46 wxbArrayString::wxbArrayString(int n) : wxArrayString(), wxObject() {
50 wxbArrayString::~wxbArrayString() {
55 * wxbTableParser constructor
57 wxbTableParser::wxbTableParser(bool header) : wxbTable(), wxbDataParser(true) {
58 separatorNum = header ? 0 : 2;
59 tableHeader = wxbArrayString();
63 * wxbTableParser destructor
65 wxbTableParser::~wxbTableParser() {
70 * Returns table header as an array of wxStrings.
72 const wxbArrayString& wxbTableParser::GetHeader() {
77 * Receives data to analyse.
79 bool wxbTableParser::Analyse(wxString str, int status) {
80 if ((status == CS_END) && (separatorNum > 0)) {
84 if (separatorNum == 3) return false;
86 if (str.Length() > 4) {
87 if ((str.GetChar(0) == '+') && (str.GetChar(str.Length()-2) == '+') && (str.GetChar(str.Length()-1) == '\n')) {
92 if ((str.GetChar(0) == '|') && (str.GetChar(str.Length()-2) == '|') && (str.GetChar(str.Length()-1) == '\n')) {
94 wxStringTokenizer tkz(str, "|", wxTOKEN_STRTOK);
96 if (separatorNum == 1) {
97 while ( tkz.HasMoreTokens() ) {
98 tableHeader.Add(tkz.GetNextToken().Trim(true).Trim(false));
101 else if (separatorNum == 2) {
102 wxbArrayString tablerow(tableHeader.GetCount());
103 while ( tkz.HasMoreTokens() ) {
104 tablerow.Add(tkz.GetNextToken().Trim(true).Trim(false));
114 * Return true table parsing has finished.
116 bool wxbTableParser::hasFinished() {
117 return (separatorNum == 3);