- for(size_t aStart = 0; aStart != std::string::npos; aStart = theName.find('[', aStart + 1)) {
- size_t anEndPos = theName.find(']', aStart + 1);
- if (anEndPos != std::string::npos) {
- std::string aSubStr = theName.substr(aStart + 1, anEndPos - aStart - 1);
+ for(size_t aStart = 0; aStart != std::wstring::npos; aStart = theName.find('[', aStart + 1)) {
+ size_t anEndPos = theName.find(L']', aStart + 1);
+ if (anEndPos != std::wstring::npos) {
+ // there could be sub-intersections, so, [[...]] case; searching for other open-bracket
+ size_t aNextStart = theName.find(L'[', aStart + 1);
+ while(aNextStart != std::wstring::npos && aNextStart < anEndPos) {
+ anEndPos = theName.find(L']', anEndPos + 1);
+ if (anEndPos == std::wstring::npos) {
+ return TDF_Label(); // invalid parentheses
+ }
+ aNextStart = theName.find(L'[', aNextStart + 1);
+ }
+ if (anEndPos == std::wstring::npos)
+ return TDF_Label(); // invalid parentheses
+ std::wstring aSubStr = theName.substr(aStart + 1, anEndPos - aStart - 1);