Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: third_party/protobuf/src/google/protobuf/io/tokenizer.cc

Issue 2495533002: third_party/protobuf: Update to HEAD (83d681ee2c) (Closed)
Patch Set: Make chrome settings proto generated file a component Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Protocol Buffers - Google's data interchange format 1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved. 2 // Copyright 2008 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/ 3 // https://developers.google.com/protocol-buffers/
4 // 4 //
5 // Redistribution and use in source and binary forms, with or without 5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are 6 // modification, are permitted provided that the following conditions are
7 // met: 7 // met:
8 // 8 //
9 // * Redistributions of source code must retain the above copyright 9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer. 10 // notice, this list of conditions and the following disclaimer.
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 // Helper class for collecting comments and putting them in the right places. 658 // Helper class for collecting comments and putting them in the right places.
659 // 659 //
660 // This basically just buffers the most recent comment until it can be decided 660 // This basically just buffers the most recent comment until it can be decided
661 // exactly where that comment should be placed. When Flush() is called, the 661 // exactly where that comment should be placed. When Flush() is called, the
662 // current comment goes into either prev_trailing_comments or detached_comments. 662 // current comment goes into either prev_trailing_comments or detached_comments.
663 // When the CommentCollector is destroyed, the last buffered comment goes into 663 // When the CommentCollector is destroyed, the last buffered comment goes into
664 // next_leading_comments. 664 // next_leading_comments.
665 class CommentCollector { 665 class CommentCollector {
666 public: 666 public:
667 CommentCollector(string* prev_trailing_comments, 667 CommentCollector(string* prev_trailing_comments,
668 vector<string>* detached_comments, 668 std::vector<string>* detached_comments,
669 string* next_leading_comments) 669 string* next_leading_comments)
670 : prev_trailing_comments_(prev_trailing_comments), 670 : prev_trailing_comments_(prev_trailing_comments),
671 detached_comments_(detached_comments), 671 detached_comments_(detached_comments),
672 next_leading_comments_(next_leading_comments), 672 next_leading_comments_(next_leading_comments),
673 has_comment_(false), 673 has_comment_(false),
674 is_line_comment_(false), 674 is_line_comment_(false),
675 can_attach_to_prev_(true) { 675 can_attach_to_prev_(true) {
676 if (prev_trailing_comments != NULL) prev_trailing_comments->clear(); 676 if (prev_trailing_comments != NULL) prev_trailing_comments->clear();
677 if (detached_comments != NULL) detached_comments->clear(); 677 if (detached_comments != NULL) detached_comments->clear();
678 if (next_leading_comments != NULL) next_leading_comments->clear(); 678 if (next_leading_comments != NULL) next_leading_comments->clear();
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 ClearBuffer(); 730 ClearBuffer();
731 } 731 }
732 } 732 }
733 733
734 void DetachFromPrev() { 734 void DetachFromPrev() {
735 can_attach_to_prev_ = false; 735 can_attach_to_prev_ = false;
736 } 736 }
737 737
738 private: 738 private:
739 string* prev_trailing_comments_; 739 string* prev_trailing_comments_;
740 vector<string>* detached_comments_; 740 std::vector<string>* detached_comments_;
741 string* next_leading_comments_; 741 string* next_leading_comments_;
742 742
743 string comment_buffer_; 743 string comment_buffer_;
744 744
745 // True if any comments were read into comment_buffer_. This can be true even 745 // True if any comments were read into comment_buffer_. This can be true even
746 // if comment_buffer_ is empty, namely if the comment was "/**/". 746 // if comment_buffer_ is empty, namely if the comment was "/**/".
747 bool has_comment_; 747 bool has_comment_;
748 748
749 // Is the comment in the comment buffer a line comment? 749 // Is the comment in the comment buffer a line comment?
750 bool is_line_comment_; 750 bool is_line_comment_;
751 751
752 // Is it still possible that we could be reading a comment attached to the 752 // Is it still possible that we could be reading a comment attached to the
753 // previous token? 753 // previous token?
754 bool can_attach_to_prev_; 754 bool can_attach_to_prev_;
755 }; 755 };
756 756
757 } // namespace 757 } // namespace
758 758
759 bool Tokenizer::NextWithComments(string* prev_trailing_comments, 759 bool Tokenizer::NextWithComments(string* prev_trailing_comments,
760 vector<string>* detached_comments, 760 std::vector<string>* detached_comments,
761 string* next_leading_comments) { 761 string* next_leading_comments) {
762 CommentCollector collector(prev_trailing_comments, detached_comments, 762 CommentCollector collector(prev_trailing_comments, detached_comments,
763 next_leading_comments); 763 next_leading_comments);
764 764
765 if (current_.type == TYPE_START) { 765 if (current_.type == TYPE_START) {
766 // Ignore unicode byte order mark(BOM) if it appears at the file 766 // Ignore unicode byte order mark(BOM) if it appears at the file
767 // beginning. Only UTF-8 BOM (0xEF 0xBB 0xBF) is accepted. 767 // beginning. Only UTF-8 BOM (0xEF 0xBB 0xBF) is accepted.
768 if (TryConsume((char)0xEF)) { 768 if (TryConsume((char)0xEF)) {
769 if (!TryConsume((char)0xBB) || !TryConsume((char)0xBF)) { 769 if (!TryConsume((char)0xBB) || !TryConsume((char)0xBF)) {
770 AddError("Proto file starts with 0xEF but not UTF-8 BOM. " 770 AddError("Proto file starts with 0xEF but not UTF-8 BOM. "
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
1130 if (!Letter::InClass(text.at(0))) 1130 if (!Letter::InClass(text.at(0)))
1131 return false; 1131 return false;
1132 if (!AllInClass<Alphanumeric>(text.substr(1))) 1132 if (!AllInClass<Alphanumeric>(text.substr(1)))
1133 return false; 1133 return false;
1134 return true; 1134 return true;
1135 } 1135 }
1136 1136
1137 } // namespace io 1137 } // namespace io
1138 } // namespace protobuf 1138 } // namespace protobuf
1139 } // namespace google 1139 } // namespace google
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698