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
16 Copyright (C) 2004 Kern Sibbald and John Walker
18 This program is free software; you can redistribute it and/or
19 modify it under the terms of the GNU General Public License
20 as published by the Free Software Foundation; either version 2
21 of the License, or (at your option) any later version.
23 This program is distributed in the hope that it will be useful,
24 but WITHOUT ANY WARRANTY; without even the implied warranty of
25 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 GNU General Public License for more details.
28 You should have received a copy of the GNU General Public License
29 along with this program; if not, write to the Free Software
30 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
33 #include "wxbtableparser.h" // class's header file
37 #include <wx/tokenzr.h>
39 #include "wxbmainframe.h"
41 #include <wx/arrimpl.cpp>
43 WX_DEFINE_OBJARRAY(wxbTable);
45 wxbArrayString::wxbArrayString(int n) : wxArrayString(), wxObject() {
49 wxbArrayString::~wxbArrayString() {
54 * wxbTableParser constructor
56 wxbTableParser::wxbTableParser() : wxbTable(), wxbDataParser(true) {
58 tableHeader = wxbArrayString();
62 * wxbTableParser destructor
64 wxbTableParser::~wxbTableParser() {
69 * Returns table header as an array of wxStrings.
71 const wxbArrayString& wxbTableParser::GetHeader() {
76 * Receives data to analyse.
78 bool wxbTableParser::Analyse(wxString str, int status) {
79 if ((status == CS_END) && (separatorNum > 0)) {
83 if (separatorNum == 3) return false;
85 if (str.Length() > 4) {
86 if ((str.GetChar(0) == '+') && (str.GetChar(str.Length()-2) == '+') && (str.GetChar(str.Length()-1) == '\n')) {
91 if ((str.GetChar(0) == '|') && (str.GetChar(str.Length()-2) == '|') && (str.GetChar(str.Length()-1) == '\n')) {
93 wxStringTokenizer tkz(str, "|", wxTOKEN_STRTOK);
95 if (separatorNum == 1) {
96 while ( tkz.HasMoreTokens() ) {
97 tableHeader.Add(tkz.GetNextToken().Trim(true).Trim(false));
100 else if (separatorNum == 2) {
101 wxbArrayString tablerow(tableHeader.GetCount());
102 while ( tkz.HasMoreTokens() ) {
103 tablerow.Add(tkz.GetNextToken().Trim(true).Trim(false));
113 * Return true table parsing has finished.
115 bool wxbTableParser::hasFinished() {
116 return (separatorNum == 3);