Update of /cvsroot/objecthandler/log4cxx-0.9.7/tests/src/util
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv25784/tests/src/util
Added Files:
Makefile.am absolutedateandtimefilter.cpp
absolutedateandtimefilter.h absolutetimefilter.cpp
absolutetimefilter.h compare.cpp compare.h controlfilter.cpp
controlfilter.h filter.cpp filter.h iso8601filter.cpp
iso8601filter.h linenumberfilter.cpp linenumberfilter.h
relativetimefilter.cpp relativetimefilter.h threadfilter.cpp
threadfilter.h transformer.cpp transformer.h
xmllineattributefilter.cpp xmllineattributefilter.h
xmlthreadfilter.cpp xmlthreadfilter.h xmltimestampfilter.cpp
xmltimestampfilter.h
Log Message:
--- NEW FILE: xmltimestampfilter.h ---
/*
* Copyright 2003,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _LOG4CXX_TESTS_UTIL_XML_TIMESTAMP_FILTER_H
#define _LOG4CXX_TESTS_UTIL_XML_TIMESTAMP_FILTER_H
#include "filter.h"
namespace log4cxx
{
class XMLTimestampFilter : public Filter
{
public:
String filter(const String& in) const throw(UnexpectedFormatException);
};
}
#endif //_LOG4CXX_TESTS_UTIL_XML_TIMESTAMP_FILTER_H
--- NEW FILE: compare.h ---
/*
* Copyright 2003,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <log4cxx/helpers/tchar.h>
namespace log4cxx
{
class Compare
{
public:
static bool compare(const String& file1, const String& file2);
private:
/// Prints file on the console.
static void outputFile(const String& file);
};
}
--- NEW FILE: filter.h ---
/*
* Copyright 2003,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _LOG4CXX_TESTS_UTIL_FILTER_H
#define _LOG4CXX_TESTS_UTIL_FILTER_H
#include <log4cxx/helpers/tchar.h>
#include <log4cxx/helpers/exception.h>
#define BASIC_PAT _T("\\[\\d*\\] (FATAL|ERROR|WARN|INFO|DEBUG)")
#define ISO8601_PAT _T("^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2},\\d{3}")
#define ABSOLUTE_DATE_AND_TIME_PAT \
_T("^\\d{1,2} .{2,6}\\.? 200\\d \\d{2}:\\d{2}:\\d{2},\\d{3}")
#define ABSOLUTE_TIME_PAT _T("^\\d{2}:\\d{2}:\\d{2},\\d{3}")
#define RELATIVE_TIME_PAT _T("^\\d{1,10}")
namespace log4cxx
{
class UnexpectedFormatException : public helpers::Exception
{
public:
UnexpectedFormatException(const String& message)
: message(message) {}
virtual String getMessage()
{ return message; }
protected:
String message;
};
class Filter
{
public:
virtual String filter(const String& in)
const throw(UnexpectedFormatException) = 0;
static String merge(const String& pattern, const String& in, const String& fmt);
static bool match(const String& pattern, const String& in);
};
}
#endif //_LOG4CXX_TESTS_UTIL_FILTER_H
--- NEW FILE: controlfilter.h ---
/*
* Copyright 2003,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _LOG4CXX_TESTS_UTIL_CONTROL_FILTER_H
#define _LOG4CXX_TESTS_UTIL_CONTROL_FILTER_H
#include "filter.h"
#include <vector>
namespace log4cxx
{
class ControlFilter : public Filter
{
public:
ControlFilter();
String filter(const String& in) const throw(UnexpectedFormatException);
ControlFilter& operator<<(const String& allowedPattern);
protected:
std::vector<String> allowedPatterns;
};
}
#endif //_LOG4CXX_TESTS_UTIL_CONTROL_FILTER_H
--- NEW FILE: transformer.cpp ---
/*
* Copyright 2003,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "transformer.h"
#include <fstream>
using namespace log4cxx;
typedef std::basic_ifstream<TCHAR> ifstream;
typedef std::basic_ofstream<TCHAR> ofstream;
void Transformer::transform(const String& in, const String& out,
const std::vector<Filter *>& filters) throw(UnexpectedFormatException)
{
String line;
USES_CONVERSION
ifstream input(T2A(in.c_str()));
ofstream output(T2A(out.c_str()));
while (!std::getline(input, line).fail())
{
for (std::vector<Filter *>::size_type i = 0; i < filters.size(); i++)
{
line = filters[i]->filter(line);
}
if (!line.empty())
{
output << line << std::endl;
}
}
}
void Transformer::transform(const String& in, const String& out,
const Filter& filter) throw(UnexpectedFormatException)
{
String line;
USES_CONVERSION
ifstream input(T2A(in.c_str()));
ofstream output(T2A(out.c_str()));
while (!std::getline(input, line).fail())
{
line = filter.filter(line);
output << line << std::endl;
}
}
--- NEW FILE: absolutedateandtimefilter.cpp ---
/*
* Copyright 2003,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "absolutedateandtimefilter.h"
using namespace log4cxx;
using namespace log4cxx::helpers;
String AbsoluteDateAndTimeFilter::filter(const String& in)
const throw(UnexpectedFormatException)
{
return merge(ABSOLUTE_DATE_AND_TIME_PAT, in, _T(""));
}
--- NEW FILE: xmltimestampfilter.cpp ---
/*
* Copyright 2003,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "xmltimestampfilter.h"
using namespace log4cxx;
using namespace log4cxx::helpers;
String XMLTimestampFilter::filter(const String& in)
const throw(UnexpectedFormatException)
{
return merge(_T("timestamp=\"\\d{10,13}\""), in, _T("timestamp=\"XXX\""));
}
--- NEW FILE: transformer.h ---
/*
* Copyright 2003,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _LOG4CXX_TESTS_UTIL_TRANSFORMER_H
#define _LOG4CXX_TESTS_UTIL_TRANSFORMER_H
#include "filter.h"
#include <vector>
namespace log4cxx
{
class Transformer
{
public:
static void transform(const String& in, const String& out,
const std::vector<Filter *>& filters) throw(UnexpectedFormatException);
static void transform(const String& in, const String& out,
const Filter& filter) throw(UnexpectedFormatException);
};
}
#endif //_LOG4CXX_TESTS_UTIL_TRANSFORMER_H
--- NEW FILE: iso8601filter.cpp ---
/*
* Copyright 2003,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "iso8601filter.h"
using namespace log4cxx;
using namespace log4cxx::helpers;
String ISO8601Filter::filter(const String& in) const throw(UnexpectedFormatException)
{
return merge(ISO8601_PAT, in, _T(""));
}
--- NEW FILE: linenumberfilter.cpp ---
/*
* Copyright 2003,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "linenumberfilter.h"
using namespace log4cxx;
using namespace log4cxx::helpers;
String LineNumberFilter::filter(const String& in) const throw(UnexpectedFormatException)
{
String temp = merge(_T(" [^ ]*[\\\\]"), in, _T(" "));
return merge(_T("\\(\\d{1,4}\\)"), temp, _T("\\(X\\)"));
}
--- NEW FILE: compare.cpp ---
/*
* Copyright 2003,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "compare.h"
#include <fstream>
typedef std::basic_ifstream<TCHAR> ifstream;
using namespace log4cxx;
bool Compare::compare(const String& file1, const String& file2)
{
USES_CONVERSION
ifstream in1(T2A(file1.c_str()));
ifstream in2(T2A(file2.c_str()));
String s1;
int lineCounter = 0;
while (!std::getline(in1, s1).fail())
{
lineCounter++;
String s2;
std::getline(in2, s2);
if (s1 != s2)
{
tcout << _T("Files [") << file1 << _T("] and [") << file2
<< _T("] differ on line ") << lineCounter << std::endl;
tcout << _T("One reads: [") << s1 << _T("].") << std::endl;
tcout << _T("Other reads:[") << s2 << _T("].") << std::endl;
outputFile(file1);
outputFile(file2);
return false;
}
}
// the second file is longer
if (in2.get() != ifstream::traits_type::eof())
{
tcout << _T("File [") << file2 << _T("] longer than file [") << file1 << _T("].")
<< std::endl;
outputFile(file1);
outputFile(file2);
return false;
}
return true;
}
void Compare::outputFile(const String& file)
{
USES_CONVERSION;
ifstream in1(T2A(file.c_str()));
String s1;
int lineCounter = 0;
tcout << _T("--------------------------------") << std::endl;
tcout << _T("Contents of ") << file << _T(":") << std::endl;
while (!std::getline(in1, s1).fail())
{
lineCounter++;
tcout << lineCounter;
if (lineCounter < 10)
{
tcout << _T(" : ");
}
else if (lineCounter < 100)
{
tcout << _T(" : ");
}
else if (lineCounter < 1000)
{
tcout << _T(" : ");
}
else
{
tcout << _T(": ");
}
tcout << s1 << std::endl;
}
}
--- NEW FILE: threadfilter.cpp ---
/*
* Copyright 2003,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "threadfilter.h"
using namespace log4cxx;
using namespace log4cxx::helpers;
String ThreadFilter::filter(const String& in)
const throw(UnexpectedFormatException)
{
return merge(_T("\\[\\d+\\]"), in, _T("\\[main]"));
}
--- NEW FILE: relativetimefilter.cpp ---
/*
* Copyright 2003,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "relativetimefilter.h"
using namespace log4cxx;
using namespace log4cxx::helpers;
String RelativeTimeFilter::filter(const String& in)
const throw(UnexpectedFormatException)
{
return merge(RELATIVE_TIME_PAT, in, _T(""));
}
--- NEW FILE: Makefile.am ---
EXTRA_DIST = $(top_srcdir)/tests/src/util/*.cpp
noinst_HEADERS= $(top_srcdir)/tests/src/util/*.h
if TESTS
noinst_LIBRARIES = libutil.a
INCLUDES = -I$(top_srcdir)/include
libutil_a_SOURCES = \
absolutetimefilter.cpp\
absolutedateandtimefilter.cpp\
compare.cpp\
controlfilter.cpp\
filter.cpp\
iso8601filter.cpp\
linenumberfilter.cpp\
relativetimefilter.cpp\
threadfilter.cpp\
transformer.cpp\
xmllineattributefilter.cpp\
xmltimestampfilter.cpp \
xmlthreadfilter.cpp
check: libutil.a
endif
--- NEW FILE: xmllineattributefilter.cpp ---
/*
* Copyright 2003,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "xmllineattributefilter.h"
using namespace log4cxx;
using namespace log4cxx::helpers;
String XMLLineAttributeFilter::filter(const String& in)
const throw(UnexpectedFormatException)
{
String temp = merge(_T("file=\"[^ ]*[\\\\]"), in, _T("file=\""));
return merge(_T("line=\"\\d{1,3}\""), temp, _T("line=\"X\""));
}
--- NEW FILE: xmlthreadfilter.h ---
/*
* Copyright 2003,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _LOG4CXX_TESTS_UTIL_XML_THREAD_FILTER_H
#define _LOG4CXX_TESTS_UTIL_XML_THREAD_FILTER_H
#include "filter.h"
namespace log4cxx
{
class XMLThreadFilter : public Filter
{
public:
String filter(const String& in) const throw(UnexpectedFormatException);
};
}
#endif //_LOG4CXX_TESTS_UTIL_XML_THREAD_FILTER_H
--- NEW FILE: relativetimefilter.h ---
/*
* Copyright 2003,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _LOG4CXX_TESTS_UTIL_REL_TIME_FILTER_H
#define _LOG4CXX_TESTS_UTIL_REL_TIME_FILTER_H
#include "filter.h"
namespace log4cxx
{
class RelativeTimeFilter : public Filter
{
public:
String filter(const String& in) const throw(UnexpectedFormatException);
};
}
#endif //_LOG4CXX_TESTS_UTIL_REL_TIME_FILTER_H
--- NEW FILE: xmllineattributefilter.h ---
/*
* Copyright 2003,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _LOG4CXX_TESTS_UTIL_XML_LINE_ATTRIBUTE_FILTER_H
#define _LOG4CXX_TESTS_UTIL_XML_LINE_ATTRIBUTE_FILTER_H
#include "filter.h"
namespace log4cxx
{
class XMLLineAttributeFilter : public Filter
{
public:
String filter(const String& in) const throw(UnexpectedFormatException);
};
}
#endif //_LOG4CXX_TESTS_UTIL_XML_LINE_ATTRIBUTE_FILTER_H
--- NEW FILE: absolutedateandtimefilter.h ---
/*
* Copyright 2003,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _LOG4CXX_TESTS_UTIL_ABS_DATE_TIME_FILTER_H
#define _LOG4CXX_TESTS_UTIL_ABS_DATE_TIME_FILTER_H
#include "filter.h"
namespace log4cxx
{
class AbsoluteDateAndTimeFilter : public Filter
{
public:
String filter(const String& in) const throw(UnexpectedFormatException);
};
}
#endif //_LOG4CXX_TESTS_UTIL_ABS_DATE_TIME_FILTER_H
--- NEW FILE: xmlthreadfilter.cpp ---
/*
* Copyright 2003,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "xmlthreadfilter.h"
using namespace log4cxx;
using namespace log4cxx::helpers;
String XMLThreadFilter::filter(const String& in)
const throw(UnexpectedFormatException)
{
return merge(_T("thread=\"\\d{1,10}\""), in, _T("thread=\"main\""));
}
--- NEW FILE: absolutetimefilter.h ---
/*
* Copyright 2003,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _LOG4CXX_TESTS_UTIL_ABS_TIME_FILTER_H
#define _LOG4CXX_TESTS_UTIL_ABS_TIME_FILTER_H
#include "filter.h"
namespace log4cxx
{
class AbsoluteTimeFilter : public Filter
{
public:
String filter(const String& in) const throw(UnexpectedFormatException);
};
}
#endif //_LOG4CXX_TESTS_UTIL_ABS_TIME_FILTER_H
--- NEW FILE: filter.cpp ---
/*
* Copyright 2003,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <boost/regex.hpp>
#include "filter.h"
using namespace log4cxx;
using namespace log4cxx::helpers;
using namespace boost;
String Filter::merge(const String& pattern, const String& in, const String& fmt)
{
USES_CONVERSION;
std::string convPattern = T2A(pattern.c_str());
std::string convIn = T2A(in.c_str());
std::string convFmt = T2A(fmt.c_str());
std::string result = RegEx(convPattern).Merge(convIn, convFmt);
return A2T(result.c_str());
}
bool Filter::match(const String& pattern, const String& in)
{
USES_CONVERSION;
std::string convPattern = T2A(pattern.c_str());
std::string convIn = T2A(in.c_str());
return RegEx(convPattern).Match(convIn);
}
--- NEW FILE: linenumberfilter.h ---
/*
* Copyright 2003,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _LOG4CXX_TESTS_UTIL_LINE_NUMBER_FILTER_H
#define _LOG4CXX_TESTS_UTIL_LINE_NUMBER_FILTER_H
#include "filter.h"
namespace log4cxx
{
class LineNumberFilter : public Filter
{
public:
String filter(const String& in) const throw(UnexpectedFormatException);
};
}
#endif //_LOG4CXX_TESTS_UTIL_LINE_NUMBER_FILTER_H
--- NEW FILE: controlfilter.cpp ---
/*
* Copyright 2003,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "controlfilter.h"
using namespace log4cxx;
using namespace log4cxx::helpers;
ControlFilter::ControlFilter()
{
}
String ControlFilter::filter(const String& in) const throw(UnexpectedFormatException)
{
int len = allowedPatterns.size();
for (int i = 0; i < len; i++)
{
if (match(allowedPatterns[i], in))
{
return in;
}
}
throw UnexpectedFormatException(String(_T("[")) + in + _T("]"));
}
ControlFilter& ControlFilter::operator<<(const String& allowedPattern)
{
allowedPatterns.push_back(allowedPattern);
return *this;
}
--- NEW FILE: iso8601filter.h ---
/*
* Copyright 2003,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _LOG4CXX_TESTS_UTIL_ISO_8601_FILTER_H
#define _LOG4CXX_TESTS_UTIL_ISO_8601_FILTER_H
#include "filter.h"
namespace log4cxx
{
class ISO8601Filter : public Filter
{
public:
String filter(const String& in) const throw(UnexpectedFormatException);
};
}
#endif //_LOG4CXX_TESTS_UTIL_ISO_8601_FILTER_H
--- NEW FILE: threadfilter.h ---
/*
* Copyright 2003,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _LOG4CXX_TESTS_UTIL_THREAD_FILTER_H
#define _LOG4CXX_TESTS_UTIL_THREAD_FILTER_H
#include "filter.h"
namespace log4cxx
{
class ThreadFilter : public Filter
{
public:
String filter(const String& in) const throw(UnexpectedFormatException);
};
}
#endif //_LOG4CXX_TESTS_UTIL_THREAD_FILTER_H
--- NEW FILE: absolutetimefilter.cpp ---
/*
* Copyright 2003,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "absolutetimefilter.h"
using namespace log4cxx;
using namespace log4cxx::helpers;
String AbsoluteTimeFilter::filter(const String& in)
const throw(UnexpectedFormatException)
{
return merge(ABSOLUTE_TIME_PAT, in, _T(""));
}
|