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 Bacula® - The Network Backup Solution
19 Copyright (C) 2004-2006 Free Software Foundation Europe e.V.
21 The main author of Bacula is Kern Sibbald, with contributions from
22 many others, a complete list can be found in the file AUTHORS.
23 This program is Free Software; you can redistribute it and/or
24 modify it under the terms of version two of the GNU General Public
25 License as published by the Free Software Foundation and included
28 This program is distributed in the hope that it will be useful, but
29 WITHOUT ANY WARRANTY; without even the implied warranty of
30 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
31 General Public License for more details.
33 You should have received a copy of the GNU General Public License
34 along with this program; if not, write to the Free Software
35 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
38 Bacula® is a registered trademark of Kern Sibbald.
39 The licensor of Bacula is the Free Software Foundation Europe
40 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
41 Switzerland, email:ftf@fsfeurope.org.
44 /* Windows debug builds set _DEBUG which is used by wxWidgets to select their
45 * debug memory allocator. Unfortunately it conflicts with Bacula's SmartAlloc.
46 * So we turn _DEBUG off since we aren't interested in things it enables.
53 #include "wxbtableparser.h" // class's header file
57 #include <wx/tokenzr.h>
59 #include "wxbmainframe.h"
61 #include <wx/arrimpl.cpp>
63 WX_DEFINE_OBJARRAY(wxbTable);
65 wxbArrayString::wxbArrayString(int n) : wxArrayString(), wxObject() {
69 wxbArrayString::~wxbArrayString() {
74 * wxbTableParser constructor
76 wxbTableParser::wxbTableParser(bool header) : wxbTable(), wxbDataParser(true) {
77 separatorNum = header ? 0 : 2;
78 tableHeader = wxbArrayString();
82 * wxbTableParser destructor
84 wxbTableParser::~wxbTableParser() {
89 * Returns table header as an array of wxStrings.
91 const wxbArrayString& wxbTableParser::GetHeader() {
96 * Receives data to analyse.
98 bool wxbTableParser::Analyse(wxString str, int status) {
99 if ((status == CS_END) && (separatorNum > 0)) {
103 if (separatorNum == 3) return false;
105 if (str.Length() > 4) {
106 if ((str.GetChar(0) == '+') && (str.GetChar(str.Length()-2) == '+') && (str.GetChar(str.Length()-1) == '\n')) {
111 if ((str.GetChar(0) == '|') && (str.GetChar(str.Length()-2) == '|') && (str.GetChar(str.Length()-1) == '\n')) {
113 wxStringTokenizer tkz(str, wxT("|"), wxTOKEN_STRTOK);
115 if (separatorNum == 1) {
116 while ( tkz.HasMoreTokens() ) {
117 tableHeader.Add(tkz.GetNextToken().Trim(true).Trim(false));
120 else if (separatorNum == 2) {
121 wxbArrayString tablerow(tableHeader.GetCount());
122 while ( tkz.HasMoreTokens() ) {
123 tablerow.Add(tkz.GetNextToken().Trim(true).Trim(false));
133 * Return true table parsing has finished.
135 bool wxbTableParser::hasFinished() {
136 return (separatorNum == 3);