kythe.io@v0.0.68-0.20240422202219-7225dbc01741/kythe/cxx/extractor/textproto/textproto_schema.cc (about) 1 /* 2 * Copyright 2019 The Kythe Authors. All rights reserved. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include "textproto_schema.h" 18 19 #include "absl/strings/ascii.h" 20 #include "absl/strings/str_split.h" 21 #include "absl/strings/string_view.h" 22 #include "absl/strings/strip.h" 23 24 namespace kythe { 25 namespace lang_textproto { 26 27 TextprotoSchema ParseTextprotoSchemaComments(absl::string_view textproto) { 28 TextprotoSchema schema; 29 30 for (absl::string_view line : absl::StrSplit(textproto, '\n')) { 31 if (absl::ConsumePrefix(&line, "#")) { 32 line = absl::StripLeadingAsciiWhitespace(line); 33 if (absl::ConsumePrefix(&line, "proto-file:")) { 34 schema.proto_file = absl::StripAsciiWhitespace(line); 35 } else if (absl::ConsumePrefix(&line, "proto-message:")) { 36 schema.proto_message = absl::StripAsciiWhitespace(line); 37 } else if (absl::ConsumePrefix(&line, "proto-import:")) { 38 schema.proto_imports.push_back(absl::StripAsciiWhitespace(line)); 39 } 40 } else if (line.empty()) { 41 // Skip blank lines. 42 continue; 43 } else { 44 // Stop searching after the start of actual textproto content. 45 break; 46 } 47 } 48 49 return schema; 50 } 51 52 } // namespace lang_textproto 53 } // namespace kythe