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