2014-01-13 14:08:43 -05:00
|
|
|
// Copyright (C) 2011, 2012 Google Inc.
|
2012-04-15 19:57:10 -04:00
|
|
|
//
|
|
|
|
// This file is part of YouCompleteMe.
|
|
|
|
//
|
|
|
|
// YouCompleteMe is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// YouCompleteMe is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
#include "LetterNode.h"
|
2012-05-06 03:01:32 -04:00
|
|
|
#include "standard.h"
|
2012-04-15 19:57:10 -04:00
|
|
|
|
|
|
|
|
2013-01-19 23:10:52 -05:00
|
|
|
namespace YouCompleteMe {
|
2012-04-15 19:57:10 -04:00
|
|
|
|
2012-06-24 18:35:00 -04:00
|
|
|
LetterNode::LetterNode( char letter, int index )
|
|
|
|
: is_uppercase_( IsUppercase( letter ) ),
|
2013-01-19 23:10:52 -05:00
|
|
|
index_( index ) {
|
2012-04-15 19:57:10 -04:00
|
|
|
}
|
|
|
|
|
2012-04-29 22:56:16 -04:00
|
|
|
|
2012-06-24 18:35:00 -04:00
|
|
|
// TODO: this class needs tests
|
2012-04-15 19:57:10 -04:00
|
|
|
LetterNode::LetterNode( const std::string &text )
|
2012-06-24 18:35:00 -04:00
|
|
|
: is_uppercase_( false ),
|
2013-01-19 23:10:52 -05:00
|
|
|
index_( -1 ) {
|
2012-04-15 19:57:10 -04:00
|
|
|
letternode_per_text_index_.resize( text.size() );
|
|
|
|
|
2013-01-19 23:10:52 -05:00
|
|
|
for ( uint i = 0; i < text.size(); ++i ) {
|
2012-04-15 19:57:10 -04:00
|
|
|
char letter = text[ i ];
|
2012-06-24 18:35:00 -04:00
|
|
|
LetterNode *node = new LetterNode( letter, i );
|
2012-04-15 19:57:10 -04:00
|
|
|
letters_[ letter ].push_back( node );
|
|
|
|
letternode_per_text_index_[ i ] = boost::shared_ptr< LetterNode >( node );
|
|
|
|
}
|
|
|
|
|
2012-05-06 03:01:32 -04:00
|
|
|
for ( int i = static_cast< int >( letternode_per_text_index_.size() ) - 1;
|
2013-01-19 23:10:52 -05:00
|
|
|
i >= 0; --i ) {
|
2012-04-15 19:57:10 -04:00
|
|
|
LetterNode *node_to_add = letternode_per_text_index_[ i ].get();
|
|
|
|
|
2013-01-19 23:10:52 -05:00
|
|
|
for ( int j = i - 1; j >= 0; --j ) {
|
2012-04-15 19:57:10 -04:00
|
|
|
letternode_per_text_index_[ j ]->PrependNodeForLetter( text[ i ],
|
|
|
|
node_to_add );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace YouCompleteMe
|