/*
 * Copyright 2015 - 2025 gary@drinkingtea.net
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
 */

#include <ox/std/def.hpp>
#include <ox/std/span.hpp>
#include <ox/std/strops.hpp>


static_assert(ox::strcmp("asdf", "hijk") < 0, "asdf < hijk");
static_assert(ox::strcmp("hijk", "asdf") > 0, "hijk > asdf");
static_assert(ox::strcmp("resize", "read") > 0, "resize > read");
static_assert(ox::strcmp("read", "resize") < 0, "read < resize");
static_assert(ox::strcmp("resize", "resize") == 0, "resize == resize");
static_assert(ox::strcmp("", "") == 0, "\"\" == \"\"");

static_assert([] {
	auto constexpr testStr = ox::Span{"asdf"};
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
	return ox::strchr(testStr.data(), 0, 4) == &testStr[4];
OX_ALLOW_UNSAFE_BUFFERS_END
}(), "ox::strchr 0");

static_assert([] {
	auto constexpr testStr = "aaaa";
	// test the const and non-const versions of ox::lastIndexOf
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
	return ox::lastIndexOf(testStr, 'a', ox::strlen(testStr)) == 3;
OX_ALLOW_UNSAFE_BUFFERS_END
}(), "ox::lastIndexOf aaaa a");

#ifndef OX_USE_STDLIB

extern "C"
size_t strlen(const char *str) {
	size_t len{};
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
	while (str[len]) { ++len; }
OX_ALLOW_UNSAFE_BUFFERS_END
	return len;
}

#endif
