LetterNodeListMap.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 "LetterNodeListMap.h"
  18. #include "standard.h"
  19. #include <algorithm>
  20. namespace YouCompleteMe {
  21. const int kNumLetters = NUM_LETTERS;
  22. static const int kLettersIndexStart = 0;
  23. static const int kNumbersIndexStart = 26;
  24. bool IsUppercase( char letter ) {
  25. return 'A' <= letter && letter <= 'Z';
  26. }
  27. int IndexForChar( char letter ) {
  28. if ( IsUppercase( letter ) )
  29. return letter + ( 'a' - 'A' );
  30. return letter;
  31. }
  32. LetterNodeListMap::LetterNodeListMap() {
  33. std::fill( letters_.begin(),
  34. letters_.end(),
  35. static_cast< std::list< LetterNode * >* >( NULL ) );
  36. }
  37. LetterNodeListMap::~LetterNodeListMap() {
  38. for ( uint i = 0; i < letters_.size(); ++i ) {
  39. delete letters_[ i ];
  40. }
  41. }
  42. bool LetterNodeListMap::HasLetter( char letter ) {
  43. int letter_index = IndexForChar( letter );
  44. std::list< LetterNode * > *list = letters_[ letter_index ];
  45. return list;
  46. }
  47. std::list< LetterNode * > &LetterNodeListMap::operator[] ( char letter ) {
  48. int letter_index = IndexForChar( letter );
  49. std::list< LetterNode * > *list = letters_[ letter_index ];
  50. if ( list )
  51. return *list;
  52. letters_[ letter_index ] = new std::list< LetterNode * >();
  53. return *letters_[ letter_index ];
  54. }
  55. std::list< LetterNode * > *LetterNodeListMap::ListPointerAt( char letter ) {
  56. return letters_[ IndexForChar( letter ) ];
  57. }
  58. bool LetterNodeListMap::HasLetter( char letter ) const {
  59. return letters_[ IndexForChar( letter ) ] != NULL;
  60. }
  61. } // namespace YouCompleteMe