[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 |
|
---|
[810] | 18 | push_back(std::move(tempName));
|
---|
[215] | 19 |
|
---|
[505] | 20 | if( i2 == std::string::npos ){
|
---|
[215] | 21 | break;
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | i = i2 + 1;
|
---|
| 25 | }
|
---|
| 26 | }
|
---|
| 27 |
|
---|
[810] | 28 | NamespaceScopes ActiveBasic::Common::Lexical::operator +(const NamespaceScopes &lhs, const NamespaceScopes &rhs)
|
---|
[669] | 29 | {
|
---|
[810] | 30 | return NamespaceScopes(lhs) += rhs;
|
---|
[669] | 31 | }
|
---|
| 32 |
|
---|
| 33 | bool NamespaceScopes::IsEqual( const NamespaceScopes &namespaceScopes ) const
|
---|
| 34 | {
|
---|
| 35 | if( this->size() != namespaceScopes.size() )
|
---|
| 36 | {
|
---|
| 37 | return false;
|
---|
| 38 | }
|
---|
[736] | 39 | return std::equal(begin(), end(), namespaceScopes.begin() );
|
---|
[669] | 40 | }
|
---|
| 41 |
|
---|
[215] | 42 | void NamespaceScopesCollection::SplitNamespace( const char *fullName, char *namespaceStr, char *simpleName ) const
|
---|
| 43 | {
|
---|
| 44 | NamespaceScopes namespaceScopes( fullName );
|
---|
| 45 | bool hasSimpleName = false;
|
---|
| 46 | while( namespaceScopes.size() > 0 ){
|
---|
| 47 | if( IsExist( namespaceScopes ) ){
|
---|
| 48 | break;
|
---|
| 49 | }
|
---|
| 50 | namespaceScopes.pop_back();
|
---|
| 51 |
|
---|
| 52 | hasSimpleName = true;
|
---|
| 53 | }
|
---|
| 54 |
|
---|
[700] | 55 | strcpy( namespaceStr, namespaceScopes.ToString().c_str() );
|
---|
[215] | 56 |
|
---|
| 57 | bool hasNamespace = false;
|
---|
| 58 | if( namespaceStr[0] ){
|
---|
| 59 | hasNamespace = true;
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | int dotLength = 0;
|
---|
| 63 | if( hasSimpleName && hasNamespace ){
|
---|
| 64 | dotLength = 1;
|
---|
| 65 | }
|
---|
| 66 |
|
---|
[700] | 67 | strcpy( simpleName, fullName + strlen( namespaceStr ) + dotLength );
|
---|
[215] | 68 | }
|
---|
| 69 |
|
---|