Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions _codeql_detected_source_root
5 changes: 2 additions & 3 deletions include/kf/ASimpleString.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

namespace kf
{
using namespace std;

///////////////////////////////////////////////////////////////////////////////////////////////////
// ASimpleString - non-owning string for NT kernel, inspired by http://docs.oracle.com/javase/7/docs/api/java/lang/String.html
Expand All @@ -17,7 +16,7 @@ namespace kf
ASimpleString();

template<class T, size_t Extent>
ASimpleString(span<T, Extent> buffer);
ASimpleString(std::span<T, Extent> buffer);

ASimpleString(_In_ const ANSI_STRING& str)
{
Expand Down Expand Up @@ -185,7 +184,7 @@ namespace kf
}

template<class T, size_t Extent>
inline ASimpleString::ASimpleString(span<T, Extent> buffer)
inline ASimpleString::ASimpleString(std::span<T, Extent> buffer)
{
setString(const_cast<void*>(reinterpret_cast<const void*>(buffer.data())), static_cast<int>(buffer.size_bytes()));
}
Expand Down
1 change: 0 additions & 1 deletion include/kf/ArrayUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

namespace kf
{
using namespace std;

template<typename... Ts>
inline constexpr std::array<std::byte, sizeof...(Ts)> makeArrayOfBytes(Ts&&... args) noexcept
Expand Down
3 changes: 1 addition & 2 deletions include/kf/Base64.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace kf
{
using namespace std;

// original implementation is taken from https://github.com/adamvr/arduino-base64/blob/master/Base64.cpp

Expand Down Expand Up @@ -33,7 +32,7 @@ namespace kf
return ((6 * input.charLength()) / 8) - numEq;
}

static int decode(const USimpleString& input, span<std::byte> output)
static int decode(const USimpleString& input, std::span<std::byte> output)
{
int inputIdx = 0;
int a4Idx = 0;
Expand Down
20 changes: 5 additions & 15 deletions include/kf/EarlyAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@

namespace kf
{
using namespace std;

template<class T = std::byte>
class EarlyAllocator
{
public:
static_assert(!is_const_v<T>, "The C++ Standard forbids containers of const elements because allocator<const T> is ill-formed.");
static_assert(!std::is_const_v<T>, "The C++ Standard forbids containers of const elements because allocator<const T> is ill-formed.");

using value_type = T;
using size_type = size_t;
using difference_type = ptrdiff_t;
using propagate_on_container_move_assignment = true_type;
using propagate_on_container_move_assignment = std::true_type;

constexpr EarlyAllocator() noexcept = default;

Expand All @@ -33,10 +32,7 @@ namespace kf
template<POOL_TYPE poolType>
T* initialize(const size_t count) noexcept
{
if (m_ptr || m_size)
{
_Xinvalid_argument("m_ptr || m_size");
}
ASSERT(!(m_ptr || m_size));

m_size = count * sizeof(T);
m_ptr = static_cast<T*>(operator new(m_size, poolType));
Expand All @@ -46,10 +42,7 @@ namespace kf

void deallocate(const T* ptr, const size_t count) noexcept
{
if (ptr != m_ptr || count * sizeof(T) > m_size)
{
_Xinvalid_argument("ptr != m_ptr || count * sizeof(T) > m_size");
}
ASSERT(ptr == m_ptr && count * sizeof(T) <= m_size);

operator delete(m_ptr);
m_ptr = nullptr;
Expand All @@ -58,10 +51,7 @@ namespace kf

_NODISCARD T* allocate(const size_t count) noexcept
{
if (!m_ptr || count * sizeof(T) > m_size)
{
_Xinvalid_argument("!m_ptr || count * sizeof(T) > m_size");
}
ASSERT(m_ptr && count * sizeof(T) <= m_size);

return m_ptr;
}
Expand Down
13 changes: 6 additions & 7 deletions include/kf/EncodingDetector.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace kf
{
using namespace std;

//////////////////////////////////////////////////////////////////////////////////
// EncodingDetector class identifies the encoding of a buffer.
Expand All @@ -13,7 +12,7 @@ namespace kf
class EncodingDetector
{
public:
EncodingDetector(span<const std::byte> buffer);
EncodingDetector(std::span<const std::byte> buffer);

enum Encoding
{
Expand All @@ -33,15 +32,15 @@ namespace kf
enum { kMinimalBufferSize = kMaximumBomLength };

private:
bool detectBom(span<const std::byte, kMaximumBomLength> bomBytes);
bool detectUtf16(span<const std::byte> buffer);
bool detectBom(std::span<const std::byte, kMaximumBomLength> bomBytes);
bool detectUtf16(std::span<const std::byte> buffer);

private:
Encoding m_encoding = Unknown;
int m_bomLength = 0;
};

inline EncodingDetector::EncodingDetector(span<const std::byte> buffer) : m_encoding(), m_bomLength()
inline EncodingDetector::EncodingDetector(std::span<const std::byte> buffer) : m_encoding(), m_bomLength()
{
if (buffer.size() < kMinimalBufferSize)
{
Expand All @@ -62,7 +61,7 @@ namespace kf
m_encoding = ANSI;
}

inline bool EncodingDetector::detectBom(span<const std::byte, kMaximumBomLength> bomBytes)
inline bool EncodingDetector::detectBom(std::span<const std::byte, kMaximumBomLength> bomBytes)
{
if (bomBytes[0] == std::byte(0xff) && bomBytes[1] == std::byte(0xfe) && (bomBytes[2] != std::byte(0) || bomBytes[3] != std::byte(0)))
{
Expand Down Expand Up @@ -102,7 +101,7 @@ namespace kf
return false;
}

inline bool EncodingDetector::detectUtf16(span<const std::byte> buffer)
inline bool EncodingDetector::detectUtf16(std::span<const std::byte> buffer)
{
int zeros[2] = {};

Expand Down
15 changes: 7 additions & 8 deletions include/kf/Hex.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,19 @@

namespace kf
{
using namespace std;

////////////////////////////////////////////////////////////////////////////
// The Hex class provides functionality to encode binary data into hexadecimal string representation
// and decode hexadecimal strings back into binary data.
class Hex
{
public:
static int encodeLen(span<const std::byte> input)
static int encodeLen(std::span<const std::byte> input)
{
return static_cast<int>(input.size() * 2);
}

static bool encode(span<const std::byte> input, _Out_ USimpleString& output)
static bool encode(std::span<const std::byte> input, _Out_ USimpleString& output)
{
if (output.maxByteLength() < encodeLen(input))
{
Expand All @@ -40,7 +39,7 @@ namespace kf
return true;
}

static int decodeLen(span<const char> input)
static int decodeLen(std::span<const char> input)
{
return static_cast<int>(input.size() / 2);
}
Expand All @@ -50,7 +49,7 @@ namespace kf
return input.charLength() / 2;
}

static bool decode(const ASimpleString& input, _Out_ span<std::byte>& output)
static bool decode(const ASimpleString& input, _Out_ std::span<std::byte>& output)
{
if (output.size() != static_cast<size_t>(decodeLen(input)))
{
Expand All @@ -74,14 +73,14 @@ namespace kf
private:
static inline const char kHexArray[] = "0123456789ABCDEF";

static array<wchar_t, 2> toHex(uint8_t b)
static std::array<wchar_t, 2> toHex(uint8_t b)
{
return { static_cast<wchar_t>(kHexArray[b >> 4]), static_cast<wchar_t>(kHexArray[b & 0xF]) };
}

static int fromHex(const array<const char, 2>& hexByte)
static int fromHex(const std::array<const char, 2>& hexByte)
{
array<int, 2> digits;
std::array<int, 2> digits;

for (int i = 0; i < 2; ++i)
{
Expand Down
5 changes: 2 additions & 3 deletions include/kf/Scanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@

namespace kf
{
using namespace std;

class Scanner
{
public:
Scanner(span<const std::byte> data) : m_data(data)
Scanner(std::span<const std::byte> data) : m_data(data)
{
}

Expand Down Expand Up @@ -70,6 +69,6 @@ namespace kf
}

private:
span<const std::byte> m_data;
std::span<const std::byte> m_data;
};
}
11 changes: 5 additions & 6 deletions include/kf/TextDetector.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

namespace kf
{
using namespace std;

///////////////////////////////////////////////////////////////////////////////////////////////////
// TextDetector class provides a utility to determine whether a given buffer contains textual data.
Expand All @@ -16,7 +15,7 @@ namespace kf
class TextDetector
{
public:
static bool isText(span<const std::byte> buffer)
static bool isText(std::span<const std::byte> buffer)
{
EncodingDetector encodingDetector(buffer);

Expand Down Expand Up @@ -62,15 +61,15 @@ namespace kf
}

template<class T>
static bool isValidTextLE(span<const T> buffer)
static bool isValidTextLE(std::span<const T> buffer)
{
return ranges::none_of(buffer, [](auto ch) { return isInvalidChar(ch); });
return std::ranges::none_of(buffer, [](auto ch) { return isInvalidChar(ch); });
}

template<class T>
static bool isValidTextBE(span<const T> buffer)
static bool isValidTextBE(std::span<const T> buffer)
{
return ranges::none_of(buffer, [](auto ch) { return isInvalidChar(swapBytes(ch)); });
return std::ranges::none_of(buffer, [](auto ch) { return isInvalidChar(swapBytes(ch)); });
}
};
}
7 changes: 3 additions & 4 deletions include/kf/USimpleString.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

namespace kf
{
using namespace std;

///////////////////////////////////////////////////////////////////////////////////////////////////
// USimpleString - non-owning string for NT kernel, inspired by http://docs.oracle.com/javase/7/docs/api/java/lang/String.html
Expand All @@ -21,7 +20,7 @@ namespace kf
USimpleString(_In_reads_bytes_(byteLength) const void* buffer, _In_ int byteLength);

template<class T, size_t Extent>
USimpleString(span<T, Extent> buffer);
USimpleString(std::span<T, Extent> buffer);

USimpleString(_Inout_ USimpleString&& another);
USimpleString(_In_ const USimpleString& another);
Expand Down Expand Up @@ -126,7 +125,7 @@ namespace kf

int copyTo(_In_ int maxCharLength, _Out_cap_(maxCharLength) WCHAR* destination) const
{
const int charsToCopy = min(maxCharLength - 1, charLength());
const int charsToCopy = (std::min)(maxCharLength - 1, charLength());

if (charsToCopy >= 0)
{
Expand Down Expand Up @@ -200,7 +199,7 @@ namespace kf
}

template<class T, size_t Extent>
inline USimpleString::USimpleString(span<T, Extent> buffer)
inline USimpleString::USimpleString(std::span<T, Extent> buffer)
{
setString(const_cast<void*>(reinterpret_cast<const void*>(buffer.data())), static_cast<int>(buffer.size_bytes()));
}
Expand Down
9 changes: 4 additions & 5 deletions include/kf/ext/timsort.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ namespace timsort
{
namespace detail
{
using namespace std;

template<class T>
inline int cmp(const T& lhs, const T& rhs)
Expand Down Expand Up @@ -101,7 +100,7 @@ namespace timsort
inline int compute_minrun(const uint64_t size)
{
const int top_bit = 64 - clzll(size);
const int shift = max(top_bit, 6) - 6;
const int shift = (std::max)(top_bit, 6) - 6;
const int minrun = static_cast<int>(size >> shift);
const uint64_t mask = (1ULL << shift) - 1;

Expand Down Expand Up @@ -218,7 +217,7 @@ namespace timsort
return;
}

swap(dst[start], dst[end]);
std::swap(dst[start], dst[end]);
start++;
end--;
}
Expand All @@ -238,7 +237,7 @@ namespace timsort
{
if (cmp(dst[size - 2], dst[size - 1]) > 0)
{
swap(dst[size - 2], dst[size - 1]);
std::swap(dst[size - 2], dst[size - 1]);
}

return 2;
Expand Down Expand Up @@ -350,7 +349,7 @@ namespace timsort
const size_t B = stack[stack_curr - 1].length;
const size_t curr = stack[stack_curr - 2].start;
size_t i, j, k;
tim_sort_resize(store, min(A, B));
tim_sort_resize(store, (std::min)(A, B));
T* storage = store->storage;

/* left merge */
Expand Down
Loading