third_party/bloaty/src/util.cc
Go to the documentation of this file.
1 // Copyright 2016 Google Inc. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "util.h"
16 
17 using absl::string_view;
18 
19 namespace bloaty {
20 
22 void Throw(const char *str, int line) {
23  throw bloaty::Error(str, __FILE__, line);
24 }
25 
27  const char* nullz =
28  static_cast<const char*>(memchr(data->data(), '\0', data->size()));
29 
30  // Return false if not NULL-terminated.
31  if (nullz == NULL) {
32  THROW("DWARF string was not NULL-terminated");
33  }
34 
35  size_t len = nullz - data->data();
36  absl::string_view val = data->substr(0, len);
37  data->remove_prefix(len + 1); // Remove NULL also.
38  return val;
39 }
40 
41 } // namespace bloaty
xds_interop_client.str
str
Definition: xds_interop_client.py:487
bloaty
Definition: bloaty.cc:69
ABSL_ATTRIBUTE_NORETURN
#define ABSL_ATTRIBUTE_NORETURN
Definition: abseil-cpp/absl/base/attributes.h:203
absl::string_view
Definition: abseil-cpp/absl/strings/string_view.h:167
bloaty::Error
Definition: bloaty/src/util.h:26
THROW
#define THROW(msg)
Definition: bloaty/src/util.h:45
data
char data[kBufferLength]
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1006
nullz
static void nullz(upb_status *status)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:2187
string_view
absl::string_view string_view
Definition: attr.cc:22
bloaty::ReadNullTerminated
absl::string_view ReadNullTerminated(absl::string_view *data)
Definition: third_party/bloaty/src/util.cc:26
regen-readme.line
line
Definition: regen-readme.py:30
bloaty::Throw
ABSL_ATTRIBUTE_NORETURN void Throw(const char *str, int line)
Definition: third_party/bloaty/src/util.cc:22
util.h
len
int len
Definition: abseil-cpp/absl/base/internal/low_level_alloc_test.cc:46


grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:49