third_party.pigweed.src/pw_assert/fake_backend.cc
Wyatt Hepler e2cbadfa0c pw_span: Switch from pw::span to std::span
Replace pw::span with std::span and "pw_span/span.h" with <span>
throughout the codebase.

Change-Id: Ib1fa873168b6093794e861611d750fcad6285d6c
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/12801
Commit-Queue: Wyatt Hepler <hepler@google.com>
Reviewed-by: Rob Mohr <mohrr@google.com>
Reviewed-by: Keir Mierle <keir@google.com>
2020-07-01 01:37:27 +00:00

68 lines
1.9 KiB
C++

// Copyright 2020 The Pigweed Authors
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License. You may obtain a copy of
// the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations under
// the License.
#include "pw_assert_test/fake_backend.h"
#include <cstring>
#include <span>
#include "pw_string/string_builder.h"
// Global that's publicly accessible to read captured assert contents.
struct pw_CapturedAssert pw_captured_assert;
bool IsDirSeparator(char c) { return c == '/' || c == '\\'; }
const char* GetFileBasename(const char* filename) {
int length = std::strlen(filename);
if (length == 0) {
return filename;
}
// Start on the last character, find the parent directory.
const char* basename = filename + std::strlen(filename) - 1;
while (basename != filename && !IsDirSeparator(*basename)) {
basename--;
}
if (IsDirSeparator(*basename)) {
basename++;
}
return basename;
}
void pw_CaptureAssert(const char* file_name,
int line_number,
const char* function_name,
const char* message,
...) {
// Triggered
pw_captured_assert.triggered = 1;
// Filename
pw_captured_assert.file_name = file_name;
// Line number
pw_captured_assert.line_number = line_number;
// Function name
pw_captured_assert.function_name = function_name;
// Message
pw::StringBuilder builder(pw_captured_assert.message);
va_list args;
va_start(args, message);
builder.FormatVaList(message, args);
va_end(args);
}