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-2006 Kern Sibbald
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 version 2 as amended with additional clauses defined in the
22 file LICENSE in the main source directory.
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 the file LICENSE for additional details.
31 /* Windows debug builds set _DEBUG which is used by wxWidgets to select their
32 * debug memory allocator. Unfortunately it conflicts with Bacula's SmartAlloc.
33 * So we turn _DEBUG off since we aren't interested in things it enables.
40 #include "wxbtableparser.h" // class's header file
44 #include <wx/tokenzr.h>
46 #include "wxbmainframe.h"
48 #include <wx/arrimpl.cpp>
50 WX_DEFINE_OBJARRAY(wxbTable);
52 wxbArrayString::wxbArrayString(int n) : wxArrayString(), wxObject() {
56 wxbArrayString::~wxbArrayString() {
61 * wxbTableParser constructor
63 wxbTableParser::wxbTableParser(bool header) : wxbTable(), wxbDataParser(true) {
64 separatorNum = header ? 0 : 2;
65 tableHeader = wxbArrayString();
69 * wxbTableParser destructor
71 wxbTableParser::~wxbTableParser() {
76 * Returns table header as an array of wxStrings.
78 const wxbArrayString& wxbTableParser::GetHeader() {
83 * Receives data to analyse.
85 bool wxbTableParser::Analyse(wxString str, int status) {
86 if ((status == CS_END) && (separatorNum > 0)) {
90 if (separatorNum == 3) return false;
92 if (str.Length() > 4) {
93 if ((str.GetChar(0) == '+') && (str.GetChar(str.Length()-2) == '+') && (str.GetChar(str.Length()-1) == '\n')) {
98 if ((str.GetChar(0) == '|') && (str.GetChar(str.Length()-2) == '|') && (str.GetChar(str.Length()-1) == '\n')) {
100 wxStringTokenizer tkz(str, wxT("|"), wxTOKEN_STRTOK);
102 if (separatorNum == 1) {
103 while ( tkz.HasMoreTokens() ) {
104 tableHeader.Add(tkz.GetNextToken().Trim(true).Trim(false));
107 else if (separatorNum == 2) {
108 wxbArrayString tablerow(tableHeader.GetCount());
109 while ( tkz.HasMoreTokens() ) {
110 tablerow.Add(tkz.GetNextToken().Trim(true).Trim(false));
120 * Return true table parsing has finished.
122 bool wxbTableParser::hasFinished() {
123 return (separatorNum == 3);