[215] | 1 | #include "stdafx.h"
|
---|
[736] | 2 | #include <algorithm>
|
---|
[215] | 3 |
|
---|
[505] | 4 | using namespace ActiveBasic::Common::Lexical;
|
---|
| 5 |
|
---|
| 6 |
|
---|
| 7 | NamespaceScopes::NamespaceScopes( const std::string &namespaceStr ){
|
---|
[215] | 8 | if( namespaceStr.size() == 0 ){
|
---|
| 9 | return;
|
---|
| 10 | }
|
---|
| 11 |
|
---|
[505] | 12 | std::string::size_type i = 0;
|
---|
[215] | 13 | while( true ){
|
---|
[505] | 14 | std::string::size_type i2 = namespaceStr.find( '.', i );
|
---|
[215] | 15 |
|
---|
[505] | 16 | std::string tempName = namespaceStr.substr( i, i2-i );
|
---|
[215] | 17 |
|
---|
| 18 | push_back( tempName );
|
---|
| 19 |
|
---|
[505] | 20 | if( i2 == std::string::npos ){
|
---|
[215] | 21 | break;
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | i = i2 + 1;
|
---|
| 25 | }
|
---|
| 26 | }
|
---|
| 27 |
|
---|
[669] | 28 | NamespaceScopes NamespaceScopes::operator+ ( const NamespaceScopes &namespaceScopes ) const
|
---|
| 29 | {
|
---|
[736] | 30 | NamespaceScopes result;
|
---|
| 31 | result.reserve( this->size() + namespaceScopes.size() );
|
---|
| 32 | result = *this;
|
---|
| 33 | result.append( namespaceScopes );
|
---|
[669] | 34 | return result;
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | bool NamespaceScopes::IsEqual( const NamespaceScopes &namespaceScopes ) const
|
---|
| 38 | {
|
---|
| 39 | if( this->size() != namespaceScopes.size() )
|
---|
| 40 | {
|
---|
| 41 | return false;
|
---|
| 42 | }
|
---|
[736] | 43 | return std::equal(begin(), end(), namespaceScopes.begin() );
|
---|
[669] | 44 | }
|
---|
| 45 |
|
---|
[215] | 46 | void NamespaceScopesCollection::SplitNamespace( const char *fullName, char *namespaceStr, char *simpleName ) const
|
---|
| 47 | {
|
---|
| 48 | NamespaceScopes namespaceScopes( fullName );
|
---|
| 49 | bool hasSimpleName = false;
|
---|
| 50 | while( namespaceScopes.size() > 0 ){
|
---|
| 51 | if( IsExist( namespaceScopes ) ){
|
---|
| 52 | break;
|
---|
| 53 | }
|
---|
| 54 | namespaceScopes.pop_back();
|
---|
| 55 |
|
---|
| 56 | hasSimpleName = true;
|
---|
| 57 | }
|
---|
| 58 |
|
---|
[700] | 59 | strcpy( namespaceStr, namespaceScopes.ToString().c_str() );
|
---|
[215] | 60 |
|
---|
| 61 | bool hasNamespace = false;
|
---|
| 62 | if( namespaceStr[0] ){
|
---|
| 63 | hasNamespace = true;
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | int dotLength = 0;
|
---|
| 67 | if( hasSimpleName && hasNamespace ){
|
---|
| 68 | dotLength = 1;
|
---|
| 69 | }
|
---|
| 70 |
|
---|
[700] | 71 | strcpy( simpleName, fullName + strlen( namespaceStr ) + dotLength );
|
---|
[215] | 72 | }
|
---|
| 73 |
|
---|