33 #include <boost/format.hpp>
37 using namespace boost;
41 const char Scope::COMPONENT_SEPARATOR =
'/';
54 string& normalizedString) {
56 throw invalid_argument(
"Empty scope string given.");
58 string::const_iterator prev = s.begin();
60 if (*prev != Scope::COMPONENT_SEPARATOR) {
61 throw invalid_argument(
64 "Invalid scope syntax for '%1%': has to begin with '%2%'")
65 % s % Scope::COMPONENT_SEPARATOR));
71 string::const_iterator next = prev + 1;
72 for (; next != s.end(); ++next) {
75 if (*next == Scope::COMPONENT_SEPARATOR) {
76 if (distance(prev, next) == 1) {
77 throw invalid_argument(
80 "Invalid scope syntax for '%1%' at char %2%: zero-length component between two '%3%'")
81 % s % distance(s.begin(), next)
82 % Scope::COMPONENT_SEPARATOR));
84 components.push_back(
string(prev + 1, next));
90 else if (!((
'a' <= *next && *next <=
'z')
91 || (
'A' <= *next && *next <=
'Z')
92 || (
'0' <= *next && *next <=
'9'))) {
93 throw invalid_argument(
96 "Invalid scope syntax for '%1%' at char %2%: invalid character '%3%'")
97 % s % distance(s.begin(), next) % *next));
102 if (prev + 1 != next) {
103 components.push_back(
string(prev + 1, next));
108 normalizedString = s;
109 if (*(--s.end()) != Scope::COMPONENT_SEPARATOR) {
110 normalizedString += Scope::COMPONENT_SEPARATOR;
115 Scope::Scope(
const string& s) :
150 for (vector<string>::const_iterator it = childScope.
components.begin();
165 for (
size_t i = 0; i < other.
components.size(); ++i) {
180 for (
size_t i = 0; i <
components.size(); ++i) {
190 unsigned int scopesize = 1;
191 for (vector<string>::const_iterator it =
components.begin();
193 scopesize += it->size() + 1;
199 for (vector<string>::const_iterator it =
components.begin();
201 std::copy(it->begin(), it->end(), cursor);
202 cursor += it->size();
209 vector<Scope> result;
214 for (
size_t requiredComponents = 0;
216 ++requiredComponents) {
219 for (
size_t i = 0; i < requiredComponents; ++i) {
223 result.push_back(super);
230 result.push_back(*
this);
245 return stream <<
"Scope[" << scope.
toString() <<
"]";