integrated changes from main repository for upcoming 1.2.5 release

This commit is contained in:
Guenter Obiltschnig 2006-10-12 15:08:28 +00:00
parent 41ee6e0ffa
commit 89111b52b3
26 changed files with 283 additions and 171 deletions

View File

@ -1,5 +1,21 @@
This is the changelog file for POCO - the C++ Portable Components.
Release 1.2.5 (2006-10-xx)
==========================
- Improved LoggingConfigurator: channel creation and configuration is now a two-step process.
This means that the previous problems with PropertyFileConfiguration and IniFileConfiguration when referencing other channels are solved.
- improved options handling: better handling of (non) ambiguities.
If both an option named "help" and one named "helper" is specified, this no longer causes ambiguity errors.
- added check for duplicate option definition
- ThreadPool bugfix: fixed a crash that occurs on Linux multiprocessor machines
(caused by an thread unsafe string assignment corrupting the heap...)
(SF# 1575315)
- improved ThreadPool performance
- XML now compiles with -DXML_UNICODE_WCHAR_T (SF# 1575174)
- fixed SF# 1572757: HTML forms can have more than one key/value pair with the same name
Release 1.2.4 (2006-10-02)
==========================
@ -513,4 +529,4 @@ building the libraries.
--
$Id: //poco/1.2/dist/CHANGELOG#9 $
$Id: //poco/1.2/dist/CHANGELOG#10 $

View File

@ -1,7 +1,7 @@
//
// Configurable.h
//
// $Id: //poco/1.2/Foundation/include/Poco/Configurable.h#1 $
// $Id: //poco/1.2/Foundation/include/Poco/Configurable.h#2 $
//
// Library: Foundation
// Package: Logging
@ -59,6 +59,13 @@ class Foundation_API Configurable
/// Every property controls a certain aspect of a
/// Formatter or Channel. For example, the PatternFormatter's
/// formatting pattern is set via a property.
///
/// NOTE: The following property names are use internally
/// by the logging framework and must not be used by
/// channels or formatters:
/// - class
/// - pattern (Channel)
/// - formatter (Channel)
{
public:
Configurable();

View File

@ -1,7 +1,7 @@
//
// FormattingChannel.h
//
// $Id: //poco/1.2/Foundation/include/Poco/FormattingChannel.h#1 $
// $Id: //poco/1.2/Foundation/include/Poco/FormattingChannel.h#2 $
//
// Library: Foundation
// Package: Logging
@ -94,6 +94,8 @@ public:
/// Only the "channel" and "formatter" properties are supported, which allow
/// setting the target channel and formatter, respectively, via the LoggingRegistry.
/// The "channel" and "formatter" properties are set-only.
///
/// Unsupported properties are passed to the attached Channel.
void open();
/// Opens the attached channel.

View File

@ -1,7 +1,7 @@
//
// SharedPtr.h
//
// $Id: //poco/1.2/Foundation/include/Poco/SharedPtr.h#4 $
// $Id: //poco/1.2/Foundation/include/Poco/SharedPtr.h#5 $
//
// Library: Foundation
// Package: Core
@ -133,8 +133,9 @@ public:
{
if (get() != ptr)
{
ReferenceCounter* pTmp = new ReferenceCounter;
release();
_pCounter = new ReferenceCounter;
_pCounter = pTmp;
_ptr = ptr;
}
return *this;
@ -144,10 +145,8 @@ public:
{
if (&ptr != this)
{
release();
_pCounter = ptr._pCounter;
_pCounter->duplicate();
_ptr = const_cast<C*>(ptr.get());
SharedPtr tmp(ptr);
swap(tmp);
}
return *this;
}
@ -157,10 +156,8 @@ public:
{
if (ptr.get() != _ptr)
{
release();
_pCounter = ptr._pCounter;
_pCounter->duplicate();
_ptr = const_cast<Other*>(ptr.get());
SharedPtr tmp(ptr);
swap(tmp);
}
return *this;
}
@ -183,6 +180,7 @@ public:
void swap(SharedPtr& ptr)
{
std::swap(_ptr, ptr._ptr);
std::swap(_pCounter, ptr._pCounter);
}
C* operator -> ()

View File

@ -1,7 +1,7 @@
//
// ThreadPool.h
//
// $Id: //poco/1.2/Foundation/include/Poco/ThreadPool.h#1 $
// $Id: //poco/1.2/Foundation/include/Poco/ThreadPool.h#2 $
//
// Library: Foundation
// Package: Threading
@ -158,6 +158,7 @@ private:
int _maxCapacity;
int _idleTime;
int _serial;
int _age;
ThreadVec _threads;
mutable FastMutex _mutex;
};

View File

@ -1,7 +1,7 @@
//
// FormattingChannel.cpp
//
// $Id: //poco/1.2/Foundation/src/FormattingChannel.cpp#1 $
// $Id: //poco/1.2/Foundation/src/FormattingChannel.cpp#2 $
//
// Library: Foundation
// Package: Logging
@ -126,8 +126,8 @@ void FormattingChannel::setProperty(const std::string& name, const std::string&
setChannel(LoggingRegistry::defaultRegistry().channelForName(value));
else if (name == "formatter")
setFormatter(LoggingRegistry::defaultRegistry().formatterForName(value));
else
Channel::setProperty(name, value);
else if (_pChannel)
_pChannel->setProperty(name, value);
}

View File

@ -1,7 +1,7 @@
//
// ThreadPool.cpp
//
// $Id: //poco/1.2/Foundation/src/ThreadPool.cpp#1 $
// $Id: //poco/1.2/Foundation/src/ThreadPool.cpp#2 $
//
// Library: Foundation
// Package: Threading
@ -146,10 +146,7 @@ int PooledThread::idleTime()
{
FastMutex::ScopedLock lock(_mutex);
if (_idle)
return (int) (time(NULL) - _idleTime);
else
return 0;
}
@ -214,11 +211,10 @@ void PooledThread::run()
{
ErrorHandler::handle();
}
_mutex.lock();
_idle = true;
_idleTime = time(NULL);
FastMutex::ScopedLock lock(_mutex);
_pTarget = 0;
_mutex.unlock();
_idleTime = time(NULL);
_idle = true;
_targetCompleted.set();
ThreadLocalStorage::clear();
_thread.setName(_name);
@ -238,7 +234,8 @@ ThreadPool::ThreadPool(int minCapacity, int maxCapacity, int idleTime):
_minCapacity(minCapacity),
_maxCapacity(maxCapacity),
_idleTime(idleTime),
_serial(0)
_serial(0),
_age(0)
{
poco_assert (minCapacity >= 1 && maxCapacity >= minCapacity && idleTime > 0);
@ -256,7 +253,8 @@ ThreadPool::ThreadPool(const std::string& name, int minCapacity, int maxCapacity
_minCapacity(minCapacity),
_maxCapacity(maxCapacity),
_idleTime(idleTime),
_serial(0)
_serial(0),
_age(0)
{
poco_assert (minCapacity >= 1 && maxCapacity >= minCapacity && idleTime > 0);
@ -383,21 +381,42 @@ void ThreadPool::collect()
void ThreadPool::housekeep()
{
bool moreThreads = true;
while (moreThreads && _threads.size() > _minCapacity)
{
moreThreads = false;
if (_threads.size() <= _minCapacity)
return;
ThreadVec idleThreads;
ThreadVec expiredThreads;
ThreadVec activeThreads;
idleThreads.reserve(_threads.size());
activeThreads.reserve(_threads.size());
for (ThreadVec::iterator it = _threads.begin(); it != _threads.end(); ++it)
{
if ((*it)->idleTime() >= _idleTime)
if ((*it)->idle())
{
(*it)->release();
_threads.erase(it);
moreThreads = true;
break;
if ((*it)->idleTime() < _idleTime)
idleThreads.push_back(*it);
else
expiredThreads.push_back(*it);
}
else activeThreads.push_back(*it);
}
int n = (int) activeThreads.size();
int limit = (int) idleThreads.size() + n;
if (limit < _minCapacity) limit = _minCapacity;
idleThreads.insert(idleThreads.end(), expiredThreads.begin(), expiredThreads.end());
_threads.clear();
for (ThreadVec::iterator it = idleThreads.begin(); it != idleThreads.end(); ++it)
{
if (n < limit)
{
_threads.push_back(*it);
++n;
}
else (*it)->release();
}
_threads.insert(_threads.end(), activeThreads.begin(), activeThreads.end());
_age = 0;
}
@ -405,6 +424,7 @@ PooledThread* ThreadPool::getThread()
{
FastMutex::ScopedLock lock(_mutex);
if (++_age == 32)
housekeep();
PooledThread* pThread = 0;
@ -420,10 +440,7 @@ PooledThread* ThreadPool::getThread()
_threads.push_back(pThread);
pThread->start();
}
else
{
throw NoThreadAvailableException();
}
else throw NoThreadAvailableException();
}
pThread->activate();
return pThread;

View File

@ -1,7 +1,7 @@
//
// ThreadPoolTest.cpp
//
// $Id: //poco/1.2/Foundation/testsuite/src/ThreadPoolTest.cpp#1 $
// $Id: //poco/1.2/Foundation/testsuite/src/ThreadPoolTest.cpp#2 $
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.

View File

@ -1,7 +1,7 @@
//
// HTMLForm.cpp
//
// $Id: //poco/1.2/Net/src/HTMLForm.cpp#2 $
// $Id: //poco/1.2/Net/src/HTMLForm.cpp#3 $
//
// Library: Net
// Package: HTML
@ -263,7 +263,7 @@ void HTMLForm::readUrl(std::istream& istr)
std::string decodedValue;
URI::decode(name, decodedName);
URI::decode(value, decodedValue);
set(decodedName, decodedValue);
add(decodedName, decodedValue);
if (ch == '&') ch = istr.get();
}
}
@ -302,7 +302,7 @@ void HTMLForm::readMultipart(std::istream& istr, PartHandler& handler)
value += (char) ch;
ch = istr.get();
}
set(name, value);
add(name, value);
}
}
}

View File

@ -1,7 +1,7 @@
//
// TCPServerParams.cpp
//
// $Id: //poco/1.2/Net/src/TCPServerParams.cpp#1 $
// $Id: //poco/1.2/Net/src/TCPServerParams.cpp#2 $
//
// Library: Net
// Package: TCPServer
@ -76,6 +76,4 @@ void TCPServerParams::setMaxQueued(int count)
}
} } // namespace Poco::Net

View File

@ -1,7 +1,7 @@
//
// LoggingConfigurator.h
//
// $Id: //poco/1.2/Util/include/Poco/Util/LoggingConfigurator.h#1 $
// $Id: //poco/1.2/Util/include/Poco/Util/LoggingConfigurator.h#2 $
//
// Library: Util
// Package: Configuration
@ -66,7 +66,7 @@ class Util_API LoggingConfigurator
/// Configuring Formatters
///
/// A formatter is configured using the "logging.formatters" property. Every
/// formatter has an internal name, which is only used for referring to it in
/// formatter has an internal name, which is only used for referring to it
/// during configuration time. This name becomes part of the property name.
/// Every formatter has a mandatory "class" property, which specifies the actual
/// class implementing the formatter. Any other properties are passed on to
@ -126,38 +126,6 @@ class Util_API LoggingConfigurator
/// logging.loggers.l1.channel.class = ConsoleChannel
/// logging.loggers.l1.channel.pattern = %s: [%p] %t
/// logging.loggers.l1.level = information
///
/// Known Problems
///
/// When using a PropertyFileConfiguration or IniFileConfiguration with the
/// LoggingConfigurator, the channels are constructed in alphabetical order
/// with regard to their internal name. When a channel (e.g., a SplitterChannel)
/// references another channel, the referenced channel must have a "higher" name
/// than the referring channel, otherwise it will not be found.
///
/// For example, the following configuration won't work:
///
/// logging.channels.c1.class = SplitterChannel
/// logging.channels.c1.channel1 = c2
/// logging.channels.c1.channel2 = c3
/// logging.channels.c2.class = ...
/// ...
/// logging.channels.c3.class = ...
/// ...
///
/// The workaround is to change the internal channel names:
///
/// logging.channels.cx.class = SplitterChannel
/// logging.channels.cx.channel1 = c1
/// logging.channels.cx.channel2 = c2
/// logging.channels.c1.class = ...
/// ...
/// logging.channels.c2.class = ...
/// ...
///
/// When using an XMLConfiguration, the channels are created in the order
/// in which they are specified in the configuration file, so this problem
/// does not occur.
{
public:
LoggingConfigurator();
@ -179,6 +147,7 @@ private:
void configureLoggers(AbstractConfiguration* pConfig);
Poco::Formatter* createFormatter(AbstractConfiguration* pConfig);
Poco::Channel* createChannel(AbstractConfiguration* pConfig);
void configureChannel(Channel* pChannel, AbstractConfiguration* pConfig);
void configureLogger(AbstractConfiguration* pConfig);
LoggingConfigurator(const LoggingConfigurator&);

View File

@ -1,7 +1,7 @@
//
// Option.h
//
// $Id: //poco/1.2/Util/include/Poco/Util/Option.h#1 $
// $Id: //poco/1.2/Util/include/Poco/Util/Option.h#2 $
//
// Library: Util
// Package: Options
@ -217,6 +217,13 @@ public:
/// Returns true if the given option string matches the
/// full name.
///
/// The option string must match the full
/// name (case insensitive).
bool matchesPartial(const std::string& option) const;
/// Returns true if the given option string partially matches the
/// full name.
///
/// The option string must partially match the full
/// name (case insensitive).

View File

@ -1,7 +1,7 @@
//
// LoggingConfigurator.cpp
//
// $Id: //poco/1.2/Util/src/LoggingConfigurator.cpp#1 $
// $Id: //poco/1.2/Util/src/LoggingConfigurator.cpp#2 $
//
// Library: Util
// Package: Configuration
@ -74,13 +74,13 @@ void LoggingConfigurator::configure(AbstractConfiguration* pConfig)
{
poco_check_ptr (pConfig);
AutoPtr<AbstractConfiguration> pFormattersConfig = pConfig->createView("logging.formatters");
AutoPtr<AbstractConfiguration> pFormattersConfig(pConfig->createView("logging.formatters"));
configureFormatters(pFormattersConfig);
AutoPtr<AbstractConfiguration> pChannelsConfig = pConfig->createView("logging.channels");
AutoPtr<AbstractConfiguration> pChannelsConfig(pConfig->createView("logging.channels"));
configureChannels(pChannelsConfig);
AutoPtr<AbstractConfiguration> pLoggersConfig = pConfig->createView("logging.loggers");
AutoPtr<AbstractConfiguration> pLoggersConfig(pConfig->createView("logging.loggers"));
configureLoggers(pLoggersConfig);
}
@ -91,8 +91,8 @@ void LoggingConfigurator::configureFormatters(AbstractConfiguration* pConfig)
pConfig->keys(formatters);
for (AbstractConfiguration::Keys::const_iterator it = formatters.begin(); it != formatters.end(); ++it)
{
AutoPtr<AbstractConfiguration> pFormatterConfig = pConfig->createView(*it);
AutoPtr<Formatter> pFormatter = createFormatter(pFormatterConfig);
AutoPtr<AbstractConfiguration> pFormatterConfig(pConfig->createView(*it));
AutoPtr<Formatter> pFormatter(createFormatter(pFormatterConfig));
LoggingRegistry::defaultRegistry().registerFormatter(*it, pFormatter);
}
}
@ -104,10 +104,16 @@ void LoggingConfigurator::configureChannels(AbstractConfiguration* pConfig)
pConfig->keys(channels);
for (AbstractConfiguration::Keys::const_iterator it = channels.begin(); it != channels.end(); ++it)
{
AutoPtr<AbstractConfiguration> pChannelConfig = pConfig->createView(*it);
AutoPtr<AbstractConfiguration> pChannelConfig(pConfig->createView(*it));
AutoPtr<Channel> pChannel = createChannel(pChannelConfig);
LoggingRegistry::defaultRegistry().registerChannel(*it, pChannel);
}
for (AbstractConfiguration::Keys::const_iterator it = channels.begin(); it != channels.end(); ++it)
{
AutoPtr<AbstractConfiguration> pChannelConfig(pConfig->createView(*it));
Channel* pChannel = LoggingRegistry::defaultRegistry().channelForName(*it);
configureChannel(pChannel, pChannelConfig);
}
}
@ -117,7 +123,7 @@ void LoggingConfigurator::configureLoggers(AbstractConfiguration* pConfig)
pConfig->keys(loggers);
for (AbstractConfiguration::Keys::const_iterator it = loggers.begin(); it != loggers.end(); ++it)
{
AutoPtr<AbstractConfiguration> pLoggerConfig = pConfig->createView(*it);
AutoPtr<AbstractConfiguration> pLoggerConfig(pConfig->createView(*it));
configureLogger(pLoggerConfig);
}
}
@ -125,7 +131,7 @@ void LoggingConfigurator::configureLoggers(AbstractConfiguration* pConfig)
Formatter* LoggingConfigurator::createFormatter(AbstractConfiguration* pConfig)
{
AutoPtr<Formatter> pFormatter = LoggingFactory::defaultFactory().createFormatter(pConfig->getString("class"));
AutoPtr<Formatter> pFormatter(LoggingFactory::defaultFactory().createFormatter(pConfig->getString("class")));
AbstractConfiguration::Keys props;
pConfig->keys(props);
for (AbstractConfiguration::Keys::const_iterator it = props.begin(); it != props.end(); ++it)
@ -139,24 +145,24 @@ Formatter* LoggingConfigurator::createFormatter(AbstractConfiguration* pConfig)
Channel* LoggingConfigurator::createChannel(AbstractConfiguration* pConfig)
{
AutoPtr<Channel> pChannel = LoggingFactory::defaultFactory().createChannel(pConfig->getString("class"));
AutoPtr<Channel> pWrapper = pChannel;
AutoPtr<Channel> pChannel(LoggingFactory::defaultFactory().createChannel(pConfig->getString("class")));
AutoPtr<Channel> pWrapper(pChannel);
AbstractConfiguration::Keys props;
pConfig->keys(props);
for (AbstractConfiguration::Keys::const_iterator it = props.begin(); it != props.end(); ++it)
{
if (*it == "pattern")
{
AutoPtr<Formatter> pPatternFormatter = new PatternFormatter(pConfig->getString(*it));
AutoPtr<Formatter> pPatternFormatter(new PatternFormatter(pConfig->getString(*it)));
pWrapper = new FormattingChannel(pPatternFormatter, pChannel);
}
else if (*it == "formatter")
{
AutoPtr<FormattingChannel> pFormattingChannel = new FormattingChannel(0, pChannel);
AutoPtr<FormattingChannel> pFormattingChannel(new FormattingChannel(0, pChannel));
if (pConfig->hasProperty("formatter.class"))
{
AutoPtr<AbstractConfiguration> pFormatterConfig = pConfig->createView(*it);
AutoPtr<Formatter> pFormatter = createFormatter(pFormatterConfig);
AutoPtr<AbstractConfiguration> pFormatterConfig(pConfig->createView(*it));
AutoPtr<Formatter> pFormatter(createFormatter(pFormatterConfig));
pFormattingChannel->setFormatter(pFormatter);
}
else pFormattingChannel->setProperty(*it, pConfig->getString(*it));
@ -166,12 +172,22 @@ Channel* LoggingConfigurator::createChannel(AbstractConfiguration* pConfig)
pWrapper = pFormattingChannel;
#endif
}
else if (*it != "class")
}
return pWrapper.duplicate();
}
void LoggingConfigurator::configureChannel(Channel* pChannel, AbstractConfiguration* pConfig)
{
AbstractConfiguration::Keys props;
pConfig->keys(props);
for (AbstractConfiguration::Keys::const_iterator it = props.begin(); it != props.end(); ++it)
{
if (*it != "pattern" && *it != "formatter" && *it != "class")
{
pChannel->setProperty(*it, pConfig->getString(*it));
}
}
return pWrapper.duplicate();
}
@ -184,8 +200,9 @@ void LoggingConfigurator::configureLogger(AbstractConfiguration* pConfig)
{
if (*it == "channel" && pConfig->hasProperty("channel.class"))
{
AutoPtr<AbstractConfiguration> pChannelConfig = pConfig->createView(*it);
AutoPtr<Channel> pChannel = createChannel(pChannelConfig);
AutoPtr<AbstractConfiguration> pChannelConfig(pConfig->createView(*it));
AutoPtr<Channel> pChannel(createChannel(pChannelConfig));
configureChannel(pChannel, pChannelConfig);
logger.setChannel(pChannel);
}
else if (*it != "name")

View File

@ -1,7 +1,7 @@
//
// Option.cpp
//
// $Id: //poco/1.2/Util/src/Option.cpp#1 $
// $Id: //poco/1.2/Util/src/Option.cpp#2 $
//
// Library: Util
// Package: Options
@ -238,6 +238,15 @@ bool Option::matchesShort(const std::string& option) const
bool Option::matchesFull(const std::string& option) const
{
std::string::size_type pos = option.find_first_of(":=");
std::string::size_type len = pos == std::string::npos ? option.length() : pos;
return len == _fullName.length()
&& icompare(option, 0, len, _fullName, 0, len) == 0;
}
bool Option::matchesPartial(const std::string& option) const
{
std::string::size_type pos = option.find_first_of(":=");
std::string::size_type len = pos == std::string::npos ? option.length() : pos;

View File

@ -1,7 +1,7 @@
//
// OptionSet.cpp
//
// $Id: //poco/1.2/Util/src/OptionSet.cpp#1 $
// $Id: //poco/1.2/Util/src/OptionSet.cpp#2 $
//
// Library: Util
// Package: Options
@ -70,6 +70,15 @@ OptionSet& OptionSet::operator = (const OptionSet& options)
void OptionSet::addOption(const Option& option)
{
poco_assert (!option.fullName().empty());
OptionVec::const_iterator it = _options.begin();
OptionVec::const_iterator itEnd = _options.end();
for (; it != itEnd; ++it)
{
if (it->fullName() == option.fullName())
{
throw DuplicateOptionException(it->fullName());
}
}
_options.push_back(option);
}
@ -97,12 +106,20 @@ const Option& OptionSet::getOption(const std::string& name, bool matchShort) con
const Option* pOption = 0;
for (Iterator it = _options.begin(); it != _options.end(); ++it)
{
if (matchShort && it->matchesShort(name) || !matchShort && it->matchesFull(name))
if (matchShort && it->matchesShort(name) || !matchShort && it->matchesPartial(name))
{
if (!pOption)
{
pOption = &*it;
else
throw AmbiguousOptionException(name);
if (!matchShort && it->matchesFull(name))
break;
}
else if (!matchShort && it->matchesFull(name))
{
pOption = &*it;
break;
}
else throw AmbiguousOptionException(name);
}
}
if (pOption)

View File

@ -1,7 +1,7 @@
//
// OptionSetTest.cpp
//
// $Id: //poco/1.2/Util/testsuite/src/OptionSetTest.cpp#1 $
// $Id: //poco/1.2/Util/testsuite/src/OptionSetTest.cpp#2 $
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
@ -55,6 +55,14 @@ OptionSetTest::~OptionSetTest()
void OptionSetTest::testOptionSet()
{
OptionSet set;
set.addOption(
Option("helper", "H", "start helper")
.required(false)
.repeatable(false));
set.addOption(
Option("help", "h", "print help text")
.required(false)
.repeatable(false));
set.addOption(
Option("include-dir", "I", "specify a search path for locating header files")
.required(false)
@ -65,18 +73,21 @@ void OptionSetTest::testOptionSet()
.required(false)
.repeatable(true)
.argument("path"));
set.addOption(
Option("insert", "it", "insert something")
.required(false)
.repeatable(true)
.argument("path"));
set.addOption(
Option("item", "", "insert something")
.required(false)
.repeatable(true)
.argument("path"));
set.addOption(
Option("include", "J", "specify a search path for locating header files")
.required(false)
.repeatable(true)
.argument("path"));
assert (set.hasOption("include", false));
assert (set.hasOption("I", true));
@ -88,8 +99,13 @@ void OptionSetTest::testOptionSet()
assert (!set.hasOption("i", false));
assert (!set.hasOption("in", false));
assert (set.hasOption("help"));
assert (set.hasOption("h", true));
assert (set.hasOption("helper"));
assert (set.hasOption("H", true));
const Option& opt1 = set.getOption("include");
assert (opt1.fullName() == "include-dir");
assert (opt1.fullName() == "include");
const Option& opt2 = set.getOption("item");
assert (opt2.fullName() == "item");
@ -97,6 +113,15 @@ void OptionSetTest::testOptionSet()
const Option& opt3 = set.getOption("I", true);
assert (opt3.fullName() == "include-dir");
const Option& opt4 = set.getOption("include-d");
assert (opt4.fullName() == "include-dir");
const Option& opt5 = set.getOption("help");
assert (opt5.fullName() == "help");
const Option& opt6 = set.getOption("helpe");
assert (opt6.fullName() == "helper");
try
{
set.getOption("in");
@ -106,6 +131,15 @@ void OptionSetTest::testOptionSet()
{
}
try
{
set.getOption("he");
fail("ambiguous - must throw");
}
catch (Poco::Util::AmbiguousOptionException&)
{
}
try
{
set.getOption("i");

View File

@ -1,7 +1,7 @@
//
// OptionTest.cpp
//
// $Id: //poco/1.2/Util/testsuite/src/OptionTest.cpp#1 $
// $Id: //poco/1.2/Util/testsuite/src/OptionTest.cpp#2 $
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
@ -124,15 +124,20 @@ void OptionTest::testMatches1()
.argument("path");
assert (incOpt.matchesShort("Iinclude"));
assert (incOpt.matchesFull("include:include"));
assert (incOpt.matchesFull("include-dir:include"));
assert (incOpt.matchesFull("inc=include"));
assert (incOpt.matchesFull("INCLUDE=include"));
assert (incOpt.matchesFull("include"));
assert (incOpt.matchesPartial("include:include"));
assert (incOpt.matchesPartial("include-dir:include"));
assert (incOpt.matchesPartial("inc=include"));
assert (incOpt.matchesPartial("INCLUDE=include"));
assert (incOpt.matchesPartial("include"));
assert (incOpt.matchesShort("I"));
assert (incOpt.matchesFull("i"));
assert (incOpt.matchesPartial("i"));
assert (!incOpt.matchesFull("include-dir2=include"));
assert (incOpt.matchesFull("include-dir:include"));
assert (incOpt.matchesFull("INClude-dir:include"));
assert (!incOpt.matchesFull("include:include"));
assert (!incOpt.matchesFull("include-dir2:include"));
assert (!incOpt.matchesPartial("include-dir2=include"));
assert (!incOpt.matchesShort("linclude"));
}
@ -145,12 +150,17 @@ void OptionTest::testMatches2()
.argument("path");
assert (!incOpt.matchesShort("Iinclude"));
assert (incOpt.matchesFull("include:include"));
assert (incOpt.matchesPartial("include:include"));
assert (incOpt.matchesPartial("include-dir:include"));
assert (incOpt.matchesPartial("inc=include"));
assert (incOpt.matchesPartial("INCLUDE=include"));
assert (incOpt.matchesPartial("I"));
assert (incOpt.matchesPartial("i"));
assert (incOpt.matchesFull("include-dir:include"));
assert (incOpt.matchesFull("inc=include"));
assert (incOpt.matchesFull("INCLUDE=include"));
assert (incOpt.matchesFull("I"));
assert (incOpt.matchesFull("i"));
assert (incOpt.matchesFull("INClude-dir:include"));
assert (!incOpt.matchesFull("include:include"));
assert (!incOpt.matchesFull("include-dir2:include"));
assert (!incOpt.matchesFull("include-dir2=include"));
assert (!incOpt.matchesShort("linclude"));

View File

@ -1,7 +1,7 @@
//
// DOMImplementation.h
//
// $Id: //poco/1.2/XML/include/Poco/DOM/DOMImplementation.h#1 $
// $Id: //poco/1.2/XML/include/Poco/DOM/DOMImplementation.h#2 $
//
// Library: XML
// Package: DOM
@ -93,6 +93,8 @@ private:
static const XMLString FEATURE_EVENTS;
static const XMLString FEATURE_MUTATIONEVENTS;
static const XMLString FEATURE_TRAVERSAL;
static const XMLString VERSION_1_0;
static const XMLString VERSION_2_0;
};

View File

@ -1,7 +1,7 @@
//
// DOMWriter.h
//
// $Id: //poco/1.2/XML/include/Poco/DOM/DOMWriter.h#1 $
// $Id: //poco/1.2/XML/include/Poco/DOM/DOMWriter.h#2 $
//
// Library: XML
// Package: DOM
@ -69,7 +69,7 @@ public:
void setEncoding(const std::string& encodingName, Poco::TextEncoding& textEncoding);
/// Sets the encoding, which will be reflected in the written XML declaration.
const XMLString& getEncoding() const;
const std::string& getEncoding() const;
/// Returns the encoding name set with setEncoding.
void setOptions(int options);
@ -97,7 +97,7 @@ public:
/// using a standard file output stream (std::ofstream).
private:
XMLString _encodingName;
std::string _encodingName;
Poco::TextEncoding* _pTextEncoding;
int _options;
std::string _newLine;
@ -107,7 +107,7 @@ private:
//
// inlines
//
inline const XMLString& DOMWriter::getEncoding() const
inline const std::string& DOMWriter::getEncoding() const
{
return _encodingName;
}

View File

@ -1,7 +1,7 @@
//
// DOMImplementation.cpp
//
// $Id: //poco/1.2/XML/src/DOMImplementation.cpp#1 $
// $Id: //poco/1.2/XML/src/DOMImplementation.cpp#2 $
//
// Library: XML
// Package: DOM
@ -51,6 +51,8 @@ const XMLString DOMImplementation::FEATURE_CORE = toXMLString("core");
const XMLString DOMImplementation::FEATURE_EVENTS = toXMLString("events");
const XMLString DOMImplementation::FEATURE_MUTATIONEVENTS = toXMLString("mutationevents");
const XMLString DOMImplementation::FEATURE_TRAVERSAL = toXMLString("traversal");
const XMLString DOMImplementation::VERSION_1_0 = toXMLString("1.0");
const XMLString DOMImplementation::VERSION_2_0 = toXMLString("2.0");
DOMImplementation::DOMImplementation()
@ -66,11 +68,11 @@ DOMImplementation::~DOMImplementation()
bool DOMImplementation::hasFeature(const XMLString& feature, const XMLString& version) const
{
XMLString lcFeature = Poco::toLower(feature);
return lcFeature == FEATURE_XML && version == "1.0" ||
lcFeature == FEATURE_CORE && version == "2.0" ||
lcFeature == FEATURE_EVENTS && version == "2.0" ||
lcFeature == FEATURE_MUTATIONEVENTS && version == "2.0" ||
lcFeature == FEATURE_TRAVERSAL && version == "2.0";
return lcFeature == FEATURE_XML && version == VERSION_1_0 ||
lcFeature == FEATURE_CORE && version == VERSION_2_0 ||
lcFeature == FEATURE_EVENTS && version == VERSION_2_0 ||
lcFeature == FEATURE_MUTATIONEVENTS && version == VERSION_2_0 ||
lcFeature == FEATURE_TRAVERSAL && version == VERSION_2_0;
}

View File

@ -1,7 +1,7 @@
//
// DOMWriter.cpp
//
// $Id: //poco/1.2/XML/src/DOMWriter.cpp#1 $
// $Id: //poco/1.2/XML/src/DOMWriter.cpp#2 $
//
// Library: XML
// Package: DOM
@ -63,7 +63,7 @@ DOMWriter::~DOMWriter()
}
void DOMWriter::setEncoding(const XMLString& encodingName, Poco::TextEncoding& textEncoding)
void DOMWriter::setEncoding(const std::string& encodingName, Poco::TextEncoding& textEncoding)
{
_encodingName = encodingName;
_pTextEncoding = &textEncoding;
@ -76,7 +76,7 @@ void DOMWriter::setOptions(int options)
}
void DOMWriter::setNewLine(const XMLString& newLine)
void DOMWriter::setNewLine(const std::string& newLine)
{
_newLine = newLine;
}
@ -101,7 +101,7 @@ void DOMWriter::writeNode(XMLByteOutputStream& ostr, const Node* pNode)
}
void DOMWriter::writeNode(const XMLString& systemId, const Node* pNode)
void DOMWriter::writeNode(const std::string& systemId, const Node* pNode)
{
std::ofstream ostr(systemId.c_str());
if (ostr.good())

View File

@ -1,7 +1,7 @@
//
// NamespaceStrategy.cpp
//
// $Id: //poco/1.2/XML/src/NamespaceStrategy.cpp#2 $
// $Id: //poco/1.2/XML/src/NamespaceStrategy.cpp#3 $
//
// Library: XML
// Package: XML
@ -186,7 +186,7 @@ void NamespacePrefixesStrategy::startElement(const XMLChar* name, const XMLChar*
XMLString attrLocal;
XMLString attrQName;
splitName(attrName, attrURI, attrLocal, attrQName);
if (!attrQName.empty()) attrQName.append(":");
if (!attrQName.empty()) attrQName += ':';
attrQName.append(attrLocal);
attributes.addAttribute(attrURI, attrLocal, attrQName, CDATA, attrValue, i < specifiedCount);
}
@ -194,7 +194,7 @@ void NamespacePrefixesStrategy::startElement(const XMLChar* name, const XMLChar*
XMLString local;
XMLString qname;
splitName(name, uri, local, qname);
if (!qname.empty()) qname.append(":");
if (!qname.empty()) qname += ':';
qname.append(local);
pContentHandler->startElement(uri, local, qname, attributes);
}
@ -208,7 +208,7 @@ void NamespacePrefixesStrategy::endElement(const XMLChar* name, ContentHandler*
XMLString local;
XMLString qname;
splitName(name, uri, local, qname);
if (!qname.empty()) qname.append(":");
if (!qname.empty()) qname += ':';
qname.append(local);
pContentHandler->endElement(uri, local, qname);
}

View File

@ -1,7 +1,7 @@
//
// ParserEngine.cpp
//
// $Id: //poco/1.2/XML/src/ParserEngine.cpp#1 $
// $Id: //poco/1.2/XML/src/ParserEngine.cpp#2 $
//
// Library: XML
// Package: XML
@ -659,18 +659,18 @@ int ParserEngine::handleExternalEntityRef(XML_Parser parser, const XML_Char* con
XMLString pubId;
if (publicId) pubId.assign(publicId);
URI uri(pThis->_context.back()->getSystemId());
uri.resolve(sysId);
URI uri(fromXMLString(pThis->_context.back()->getSystemId()));
uri.resolve(fromXMLString(sysId));
if (pThis->_pEntityResolver)
{
pEntityResolver = pThis->_pEntityResolver;
pInputSource = pEntityResolver->resolveEntity(publicId ? &pubId : 0, uri.toString());
pInputSource = pEntityResolver->resolveEntity(publicId ? &pubId : 0, toXMLString(uri.toString()));
}
if (!pInputSource && pThis->_externalGeneralEntities)
{
pEntityResolver = &defaultResolver;
pInputSource = pEntityResolver->resolveEntity(publicId ? &pubId : 0, uri.toString());
pInputSource = pEntityResolver->resolveEntity(publicId ? &pubId : 0, toXMLString(uri.toString()));
}
if (pInputSource)
@ -719,8 +719,13 @@ void ParserEngine::handleComment(void* userData, const XML_Char* data)
{
ParserEngine* pThis = reinterpret_cast<ParserEngine*>(userData);
#if defined(XML_UNICODE_WCHAR_T)
if (pThis->_pLexicalHandler)
pThis->_pLexicalHandler->comment(data, 0, (int) wcslen(data));
#else
if (pThis->_pLexicalHandler)
pThis->_pLexicalHandler->comment(data, 0, (int) strlen(data));
#endif
}

View File

@ -1,7 +1,7 @@
//
// SAXParser.cpp
//
// $Id: //poco/1.2/XML/src/SAXParser.cpp#1 $
// $Id: //poco/1.2/XML/src/SAXParser.cpp#2 $
//
// Library: XML
// Package: SAX
@ -222,7 +222,7 @@ void SAXParser::parse(const XMLString& systemId)
}
entityResolver.releaseInputSource(pInputSource);
}
else throw XMLException("Cannot resolve system identifier", systemId);
else throw XMLException("Cannot resolve system identifier", fromXMLString(systemId));
}

View File

@ -1,7 +1,7 @@
//
// XMLFilterImpl.cpp
//
// $Id: //poco/1.2/XML/src/XMLFilterImpl.cpp#1 $
// $Id: //poco/1.2/XML/src/XMLFilterImpl.cpp#2 $
//
// Library: XML
// Package: SAX
@ -132,7 +132,7 @@ void XMLFilterImpl::setFeature(const XMLString& featureId, bool state)
if (_pParent)
_pParent->setFeature(featureId, state);
else
throw SAXNotRecognizedException(featureId);
throw SAXNotRecognizedException(fromXMLString(featureId));
}
@ -141,7 +141,7 @@ bool XMLFilterImpl::getFeature(const XMLString& featureId) const
if (_pParent)
return _pParent->getFeature(featureId);
else
throw SAXNotRecognizedException(featureId);
throw SAXNotRecognizedException(fromXMLString(featureId));
}
@ -150,7 +150,7 @@ void XMLFilterImpl::setProperty(const XMLString& propertyId, const XMLString& va
if (_pParent)
_pParent->setProperty(propertyId, value);
else
throw SAXNotRecognizedException(propertyId);
throw SAXNotRecognizedException(fromXMLString(propertyId));
}
@ -159,7 +159,7 @@ void XMLFilterImpl::setProperty(const XMLString& propertyId, void* value)
if (_pParent)
_pParent->setProperty(propertyId, value);
else
throw SAXNotRecognizedException(propertyId);
throw SAXNotRecognizedException(fromXMLString(propertyId));
}
@ -168,7 +168,7 @@ void* XMLFilterImpl::getProperty(const XMLString& propertyId) const
if (_pParent)
return _pParent->getProperty(propertyId);
else
throw SAXNotRecognizedException(propertyId);
throw SAXNotRecognizedException(fromXMLString(propertyId));
}

View File

@ -1,7 +1,7 @@
//
// XMLWriter.cpp
//
// $Id: //poco/1.2/XML/src/XMLWriter.cpp#1 $
// $Id: //poco/1.2/XML/src/XMLWriter.cpp#2 $
//
// Library: XML
// Package: XML
@ -39,6 +39,7 @@
#include "Poco/XML/XMLException.h"
#include "Poco/SAX/AttributesImpl.h"
#include "Poco/UTF8Encoding.h"
#include "Poco/UTF16Encoding.h"
#include <sstream>
@ -682,7 +683,7 @@ void XMLWriter::addNamespaceAttributes(AttributeMap& attributeMap)
if (!prefix.empty())
{
qname.append(MARKUP_COLON);
qname.append(toXMLString(MARKUP_COLON));
qname.append(prefix);
}
attributeMap[qname] = uri;
@ -705,7 +706,7 @@ void XMLWriter::addAttributes(AttributeMap& attributeMap, const Attributes& attr
if (!prefix.empty())
{
qname = prefix;
qname.append(MARKUP_COLON);
qname.append(toXMLString(MARKUP_COLON));
}
else qname.clear();
qname.append(localName);
@ -746,7 +747,7 @@ void XMLWriter::writeXML(XMLChar ch) const
}
void XMLWriter::writeName(const std::string& prefix, const std::string& localName)
void XMLWriter::writeName(const XMLString& prefix, const XMLString& localName)
{
if (prefix.empty())
{