Skip to content
Merged
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
9 changes: 8 additions & 1 deletion lib/ts/MemView.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,14 @@
#include <ts/MemView.h>
#include <sstream>
#include <ctype.h>
#include <ts/ink_platform.h>

namespace ts
{
StringView::StringView(const char *s) : _ptr(s), _size(strlen(s))
{
}

int
memcmp(MemView const &lhs, MemView const &rhs)
{
Expand Down Expand Up @@ -69,7 +74,9 @@ intmax_t
svtoi(StringView src, StringView *out, int base)
{
static const int8_t convert[256] = {
// 0 1 2 3 4 5 6 7 8 9 A B C D E F
/* [can't do this nicely because clang format won't allow exdented comments]
0 1 2 3 4 5 6 7 8 9 A B C D E F
*/
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 00
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 10
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 20
Expand Down
27 changes: 24 additions & 3 deletions lib/ts/MemView.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,32 @@ namespace ts
class MemView;
class StringView;

/// Compare the memory in two views.
/// Return based on the first different byte. If one argument is a prefix of the other, the prefix
/// is considered the "smaller" value.
/// @return
/// - -1 if @a lhs byte is less than @a rhs byte.
/// - 1 if @a lhs byte is greater than @a rhs byte.
/// - 0 if the views contain identical memory.
int memcmp(MemView const &lhs, MemView const &rhs);
/// Compare the strings in two views.
/// Return based on the first different character. If one argument is a prefix of the other, the prefix
/// is considered the "smaller" value.
/// @return
/// - -1 if @a lhs char is less than @a rhs char.
/// - 1 if @a lhs char is greater than @a rhs char.
/// - 0 if the views contain identical strings.
int strcmp(StringView const &lhs, StringView const &rhs);
/// Compare the strings in two views.
/// Return based on the first different character. If one argument is a prefix of the other, the prefix
/// is considered the "smaller" value. The values are compared ignoring case.
/// @return
/// - -1 if @a lhs char is less than @a rhs char.
/// - 1 if @a lhs char is greater than @a rhs char.
/// - 0 if the views contain identical strings.
///
/// @internal Why not <const&>? Because the implementation would make copies anyway, might as well save
/// the cost of passing the pointers.
int strcasecmp(StringView lhs, StringView rhs);

/** Convert the text in @c StringView @a src to a numeric value.
Expand Down Expand Up @@ -837,9 +861,6 @@ inline constexpr StringView::StringView(const char *ptr, size_t n) : _ptr(ptr),
inline constexpr StringView::StringView(const char *start, const char *end) : _ptr(start), _size(end - start)
{
}
inline StringView::StringView(const char *s) : _ptr(s), _size(strlen(s))
{
}
inline constexpr StringView::StringView(std::nullptr_t) : _ptr(nullptr), _size(0)
{
}
Expand Down