/*
 * 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 "def.hpp"
#include "strops.hpp"

OX_ALLOW_UNSAFE_BUFFERS_BEGIN

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 testStr = "asdf";
OX_CLANG_NOWARN_BEGIN(-Wunsafe-buffer-usage)
	return ox::strchr(testStr, 0, 4) == &testStr[4];
OX_CLANG_NOWARN_END
}(), "ox::strchr 0");

static_assert([] {
	int retval = 0;
	auto testStr = "aaaa";
	// test the const and non-const versions of ox::lastIndexOf
	retval |= !(ox::lastIndexOf(const_cast<char*>(testStr), 'a', ox::strlen(testStr)) == 3);
	retval |= !(ox::lastIndexOf(testStr, 'a', ox::strlen(testStr)) == 3);
	return retval == 0;
}(), "ox::lastIndexOf aaaa a");

#ifndef OX_USE_STDLIB

extern "C"
std::size_t strlen(const char *str) {
	std::size_t len = 0;
	for (; str[len]; len++);
	return len;
}

#endif

OX_ALLOW_UNSAFE_BUFFERS_END