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 || (*next ==
'_') || (*next ==
'-'))) {
94 throw invalid_argument(
97 "Invalid scope syntax for '%1%' at char %2%: invalid character '%3%'")
98 % s % distance(s.begin(), next) % *next));
103 if (prev + 1 != next) {
104 components.push_back(
string(prev + 1, next));
109 normalizedString = s;
110 if (*(--s.end()) != Scope::COMPONENT_SEPARATOR) {
111 normalizedString += Scope::COMPONENT_SEPARATOR;
116 Scope::Scope(
const string& s) :
151 for (vector<string>::const_iterator it = childScope.
components.begin();
166 for (
size_t i = 0; i < other.
components.size(); ++i) {
181 for (
size_t i = 0; i <
components.size(); ++i) {
191 unsigned int scopesize = 1;
192 for (vector<string>::const_iterator it =
components.begin();
194 scopesize += it->size() + 1;
200 for (vector<string>::const_iterator it =
components.begin();
202 std::copy(it->begin(), it->end(), cursor);
203 cursor += it->size();
210 vector<Scope> result;
215 for (
size_t requiredComponents = 0;
217 ++requiredComponents) {
220 for (
size_t i = 0; i < requiredComponents; ++i) {
224 result.push_back(super);
231 result.push_back(*
this);
246 return stream <<
"Scope[" << scope.
toString() <<
"]";