Newer
Older
/*
Copyright (C) 2011 Adam Wardyński, Tomasz Śniatowski, Paweł Kędzia,
Adam Radziszewski, Bartosz Broda
Part of the WCCL project
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your option)
any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the LICENSE, COPYING.LESSER and COPYING files for more details.
#include <libwccl/lexicon/lexicon.h>
#include <libpwrutils/util.h>
#include <libwccl/exception.h>
Adam Radziszewski
committed
#include <boost/foreach.hpp>
boost::shared_ptr<StrSet> Lexicon::translate(const UnicodeString &key) const
boost::shared_ptr<StrSet> ret_set = boost::make_shared<StrSet>();
map_t::const_iterator i = map_.find(key);
if (i == map_.end()) {
return ret_set;
}
BOOST_FOREACH (const UnicodeString& s, i->second){
ret_set->insert(s);
}
boost::shared_ptr<StrSet> Lexicon::translate(const StrSet& set) const
{
boost::shared_ptr<StrSet> ret_set = boost::make_shared<StrSet>();
Adam Radziszewski
committed
BOOST_FOREACH (const UnicodeString& s, set.get_value()) {
boost::shared_ptr<StrSet> v = translate(s);
if (!v->empty()) {
BOOST_FOREACH(const UnicodeString& s, v->contents()){
ret_set->insert(s);
}
}
}
return ret_set;
}
void Lexicon::insert(const UnicodeString& key, const UnicodeString& value)
{
if (key.isEmpty()) {
throw InvalidArgument("key", "Empty key string in lexicon.");
throw InvalidArgument("value", "Empty value string in lexicon.");