LetterNode.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright (C) 2011, 2012 Google Inc.
  2. //
  3. // This file is part of YouCompleteMe.
  4. //
  5. // YouCompleteMe is free software: you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation, either version 3 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // YouCompleteMe is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
  17. #include "LetterNode.h"
  18. #include "standard.h"
  19. namespace YouCompleteMe {
  20. LetterNode::LetterNode( char letter, int index )
  21. : is_uppercase_( IsUppercase( letter ) ),
  22. index_( index ) {
  23. }
  24. // TODO: this class needs tests
  25. LetterNode::LetterNode( const std::string &text )
  26. : is_uppercase_( false ),
  27. index_( -1 ) {
  28. letternode_per_text_index_.resize( text.size() );
  29. for ( uint i = 0; i < text.size(); ++i ) {
  30. char letter = text[ i ];
  31. LetterNode *node = new LetterNode( letter, i );
  32. letters_[ letter ].push_back( node );
  33. letternode_per_text_index_[ i ] = boost::shared_ptr< LetterNode >( node );
  34. }
  35. for ( int i = static_cast< int >( letternode_per_text_index_.size() ) - 1;
  36. i >= 0; --i ) {
  37. LetterNode *node_to_add = letternode_per_text_index_[ i ].get();
  38. for ( int j = i - 1; j >= 0; --j ) {
  39. letternode_per_text_index_[ j ]->PrependNodeForLetter( text[ i ],
  40. node_to_add );
  41. }
  42. }
  43. }
  44. } // namespace YouCompleteMe