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-2005 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.
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(bool header) : wxbTable(), wxbDataParser(true) {
57 separatorNum = header ? 0 : 2;
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, wxT("|"), 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);