// Returns the length of the given null terminated c-string.
constexpr size_t StrLen(constchar* str) {
size_t str_len = 0; for (str_len = 0; str[str_len] != '\0'; ++str_len)
; return str_len;
}
// Finds the length of the build folder prefix from the file path. // TODO(ssid): Strip prefixes from stored strings in the binary. This code only // skips the prefix while reading the file name strings at runtime.
constexpr size_t StrippedFilePathPrefixLength() {
constexpr char path[] = __FILE__; // Only keep the file path starting from the src directory. #ifdefined(__clang__) && defined(_WIN32)
constexpr char stripped[] = "base\\location.cc"; #else
constexpr char stripped[] = "base/location.cc"; #endif
constexpr size_t path_len = StrLen(path);
constexpr size_t stripped_len = StrLen(stripped);
static_assert(path_len >= stripped_len, "Invalid file path for base/location.cc."); return path_len - stripped_len;
}
// Returns true if the |name| string has |prefix_len| characters in the prefix // and the suffix matches the |expected| string. // TODO(ssid): With C++20 we can make base::EndsWith() constexpr and use it // instead.
constexpr bool StrEndsWith(constchar* name,
size_t prefix_len, constchar* expected) { const size_t name_len = StrLen(name); const size_t expected_len = StrLen(expected); if (name_len != prefix_len + expected_len) returnfalse; for (size_t i = 0; i < expected_len; ++i) { if (name[i + prefix_len] != expected[i]) returnfalse;
} return true;
}
#ifdefined(__clang__) && defined(_WIN32)
static_assert(StrEndsWith(__FILE__, kStrippedPrefixLength, "base\\location.cc"), "The file name does not match the expected prefix format."); #else
static_assert(StrEndsWith(__FILE__, kStrippedPrefixLength, "base/location.cc"), "The file name does not match the expected prefix format."); #endif
Location::Location(constchar* function_name, constchar* file_name, int line_number, constvoid* program_counter)
: function_name_(function_name),
file_name_(file_name),
line_number_(line_number),
program_counter_(program_counter) { #if !BUILDFLAG(IS_NACL) // The program counter should not be null except in a default constructed // (empty) Location object. This value is used for identity, so if it doesn't // uniquely identify a location, things will break. // // The program counter isn't supported in NaCl so location objects won't work // properly in that context.
DCHECK(program_counter); #endif
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.