34#include <NDEVR/Buffer.h>
35#include <NDEVR/ObjectInfo.h>
36#include <NDEVR/StringStream.h>
60 friend class UTF8Iterator;
86 template<std::
size_t N>
124 template <
class t_type>
172 template<
size_t t_size>
176 return indexOf(view, ignore_case, start_index);
226 NDEVR_BASE_API
uint04 indexOf(
const char* sub_string,
char escape_char,
bool ignore_case =
false,
uint04 start_index = 0)
const;
258 NDEVR_BASE_API StringViewBuffer
split(
char delimiter,
bool preserve_empty =
true)
const;
277 NDEVR_BASE_API StringViewBuffer
split(
const Buffer<char>& delimiter,
bool preserve_empty =
true)
const;
287 NDEVR_BASE_API
void splitString(
char delimiter, StringViewBuffer& strings,
bool preserve_empty =
true)
const;
344 uint08 hash_value = 5381U;
345 for (
const char* n_value = value; *n_value; n_value++)
347 hash_value = ((hash_value << 5) + hash_value) + cast<uint08>(*n_value);
489 if (value[i] != (*
this)[i])
503 if (value[i] != (*
this)[i])
506 return value[
size()] ==
'\0';
513 template<std::
size_t t_size>
516 if (t_size <=
size())
520 if (
string[i] != (*
this)[i])
523 return string[
size()] ==
'\0';
535 if (value[i] != (*
this)[i])
538 return value[
size()] !=
'\0';
545 template<std::
size_t t_size>
548 if (t_size <=
size())
550 if (
string[
size()] !=
'\0')
552 return memcmp(
string,
begin(),
sizeof(
char) *
size()) != 0;
565 if (value[i] != (*
this)[i])
594 template<std::
size_t t_size>
640 [[nodiscard]]
constexpr const char*
begin()
const
649 [[nodiscard]]
constexpr const char*
begin(
uint04 idx_offset)
const
657 [[nodiscard]]
constexpr const char*
end()
const
666 [[nodiscard]]
constexpr bool contains(
char c)
const
668 for (
const char& iter : *
this)
700 [[nodiscard]] NDEVR_BASE_API
char last()
const;
725 const char* n_value = value;
726 for (; *n_value; ++n_value)
741 const wchar* n_value = value;
742 for (; *n_value; ++n_value)
748 else if (*n_value < 0x800)
754 uint04 cp = (*n_value << 16);
786 return value.
size() == 0;
796 return value.
size() > 0;
813 static const bool Enum =
false;
855 struct equal_to<
NDEVR::StringView>
857 using is_transparent = std::true_type;
858 bool operator()(
const StringView& a,
const String& b)
const {
return a == b; }
859 bool operator()(
const StringView& a,
const StringView& b)
const {
return a == b; }
860 bool operator()(
const StringView& a,
const char* b)
const {
return a == b; }
861 template<std::
size_t N>
862 bool operator()(
const StringView& a,
const char(&b)[N]) {
return a == b; }
863 template<std::
size_t N>
864 bool operator()(
const char(&a)[N],
const StringView& b) {
return a == b; }
870 struct hash<StringView>
872 using is_transparent = std::true_type;
873 constexpr size_t operator()(
const StringView& s)
const noexcept
875 return static_cast<size_t>(s.hash());
877 constexpr size_t operator()(
const char* s)
const noexcept
881 NDEVR_BASE_API
size_t operator()(
const String& s)
const;
883 constexpr size_t operator()(
const char(&s)[N])
const noexcept
894 NDEVR_BASE_API istream&
operator>>(istream& in, String&
string);
901 NDEVR_BASE_API ostream& operator<<(ostream& in,
const String&
string);
The equivelent of std::vector but with a bit more control.
This class is like a string view, but may optionally store the data internally Useful if the return t...
static void fromString(const StringView &string, t_type &value)
Logic for converting an object from an NDEVR API String allowing it to be used automatically with get...
The core String View class for the NDEVR API.
StringView substr(uint04 start) const
Creates a substring from a given start position, to the end of the string.
bool isSameNoCase(const StringView &s) const
Checks whether two strings match in a case-insensitive way.
uint04 indexOf(const char &sub_string, uint04 start_pos, uint04 size) const
Given a substring specified by the input, returns the first index of that string, if it exists.
constexpr bool operator==(const char *const value) const
Checks equality with a null-terminated C string.
String predictNextStringIncrement() const
Looks in the string for key markers that might be an index, and attempts to increment the index.
char last() const
Returns the last character in the string view.
static constexpr uint04 str_len(const char *value)
constexpr method to get the length of a null-terminated string at compile time
bool beginsWith(const StringView &s, bool ignore_case=false) const
Tests if this String starts with the specified prefix.
bool matchesWildcard(const StringView &pattern) const
Checks whether two strings match allowing '' to be used as a wildcard pattern.
bool operator==(const String &value) const
Checks equality with a String object.
static bool AlphaNumericCompare(const StringView &left, const StringView &right)
Compares two strings given their alpha-numeric determined value.
constexpr const char * end() const
Returns a pointer to one past the last character of the string data.
constexpr uint08 hashUpper() const
Creates a simple, quick hash of the object.
uint04 indexOf(const char *sub_string, char escape_char, bool ignore_case=false, uint04 start_index=0) const
Given a substring specified by the input, returns the first index of that string, if it exists.
bool isLessNoCase(const StringView &other) const
Case-insensitive less-than comparison.
constexpr bool operator==(const char(&string)[t_size])
Checks equality with a static char array.
String toTitleString() const
Formats the string to be a title, capitalizing important characters and replacing underscores with sp...
constexpr bool operator!=(const char *const value) const
Checks inequality with a null-terminated C string.
bool isNullTerminated() const
Checks whether the underlying string data is null terminated.
const char * m_start
Pointer to the beginning of the string data.
constexpr StringView(const char *string)
String Constructor for null terminated array of chars.
constexpr StringView & operator=(const char(&string)[t_size])
Assignment operator from a static char array.
constexpr uint08 hashLower() const
Creates a simple, quick hash of the object.
constexpr StringView()
Constructor used to create an empty StringView.
void splitString(const Buffer< char > &delimiter, StringViewBuffer &strings, bool preserve_empty=true) const
Given multiple delimiter, breaks the string into subsections, and APPENDS each substring to the given...
bool operator!=(const String &value) const
Checks inequality with a String object.
uint04 lastIndexOf(const char value, bool ignore_case=false) const
Given a value specified by the input, returns the last index of that char, if it exists.
StringView(String &&s)=delete
Deleted move constructor from String to prevent dangling views.
void removeLast(uint04 count=1)
Removes the specified number of characters from the end of the view.
constexpr const char * begin(uint04 idx_offset) const
Returns a pointer offset from the beginning of the string data.
constexpr const char * begin() const
Returns a pointer to the beginning of the string data.
StringAllocatingView shortenString(uint04 size) const
Shortans the string to the max size provided.
constexpr StringView(const char(&string)[N])
String Constructor for static char arrays.
constexpr bool operator!=(const char(&string)[t_size])
Checks inequality with a static char array.
constexpr StringView(const StringView &other) noexcept
Copy constructor for StringView.
constexpr StringView & operator=(const char *value)
Assignment operator from a null-terminated C string.
static StringViewBuffer Convert(const StringBuffer &strings)
Converts a StringBuffer into a StringViewBuffer.
bool hasSubString(const StringView &sub_string, bool ignore_case=false, uint04 initial_index=0) const
Tests if this String contains the specified substring.
constexpr const char & operator[](const uint04 idx) const
Accesses the character at the given index.
bool isNumeric() const
Checks to see if the string is a numeric string.
uint04 m_size
The byte length of the string view.
void splitString(char delimiter, StringViewBuffer &strings, bool preserve_empty=true) const
Given multiple delimiter, breaks the string into subsections, and APPENDS each substring to the given...
StringView & operator=(const String &value)
Assignment operator from a String object.
uint04 indexOf(const char(&value)[t_size], bool ignore_case, uint04 start_index=0) const
Template overload of indexOf for static char arrays.
uint04 indexOf(const StringView &sub_string, bool ignore_case=false, uint04 start_index=0) const
Given a substring specified by the input, returns the first index of that string, if it exists.
constexpr StringView & operator=(const StringView &value)
Copy assignment operator from another StringView.
uint04 count(char c) const
Counts the number of occurrences of the given character.
constexpr uint08 hash() const
Creates a simple, quick hash of the object.
static constexpr uint08 hash(const char *value)
constexpr method to hash a value.
StringAllocatingView toLower() const
changes all upper case characters into lower case characters.
StringView & operator=(String &&value)=delete
Deleted move assignment from String to prevent dangling views.
StringViewBuffer split(char delimiter, bool preserve_empty=true) const
Given a delimiter, breaks the string into subsections, returning an array of each subsection.
bool operator>(const StringView &value) const
Greater-than comparison operator using lexicographic ordering.
constexpr StringView(StringView &&other) noexcept
Move constructor for StringView.
constexpr bool contains(char c) const
Checks whether the string view contains the given character.
StringView substr(uint04 start, uint04 end) const
Creates a substring from a given start position, to the given end position, non-inclusive of the end ...
void addToSize(uint04 size)
Increases the reported size of the string view by the given amount.
constexpr StringView(const char *const string, uint04 size)
String Constructor char arrays when the size is known.
StringView & trimWhiteSpace()
Trims leading and trailing whitespace from the string view.
t_type getAs() const
Converts a string into an object.
constexpr bool operator==(const StringView &value) const
Checks equality with another StringView.
void removeFirst(uint04 count=1)
Removes the specified number of characters from the beginning of the view.
StringView splitPart(char delimiter, uint04 index) const
Returns a single part from splitting the string by the given delimiter.
uint04 indexOf(const char &sub_string, uint04 start_pos) const
Given a substring specified by the input, returns the first index of that string, if it exists.
uint04 indexOf(const char *sub_string, bool ignore_case, uint04 start_index, uint04 size) const
Given a substring specified by the input, returns the first index of that string, if it exists.
bool endsWith(const StringView &s, bool ignore_case=false) const
Tests if this String ends with the specified suffix.
uint04 lastIndexOf(const char *sub_string, bool ignore_case=false) const
Given a substring specified by the input, returns the last index of that string, if it exists.
void ensureNullTerminated(String &s)
This makes the string null terminated, if needed, using the provided string as the new buffer.
constexpr bool operator!=(const StringView &value) const
Checks inequality with another StringView.
static constexpr uint04 str_len(const wchar *value)
constexpr method to get the UTF8 length of a null-terminated string at compile time
static void Convert(StringBuffer &&strings)=delete
Deleted overload to prevent converting from rvalue StringBuffer which would create dangling views.
StringViewBuffer split(const Buffer< char > &delimiter, bool preserve_empty=true) const
Given multiple delimiter, breaks the string view into subsections, returning an array of each subsect...
StringAllocatingView insertNewLines(uint04 max_line_size) const
Finds key areas to insert new lines such that the rows are at most, the length provided.
bool isGreaterNoCase(const StringView &other) const
Case-insensitive greater-than comparison.
static StringBuffer Convert(const StringViewBuffer &views)
Converts a StringViewBuffer into a StringBuffer by copying each view into a String.
constexpr uint04 size() const
Returns the byte size of this string view.
uint04 fromHex() const
Converts a hex value into an unsigned 4 byte number.
StringAllocatingView toUpper() const
changes all lower case characters into upper case characters.
bool operator<(const StringView &value) const
Less-than comparison operator using lexicographic ordering.
uint04 indexOf(const char &sub_string) const
Given a substring specified by the input, returns the first index of that string, if it exists.
The core String class for the NDEVR API.
UTF8Iterator(const StringView &string)
Constructs a UTF8Iterator from a StringView.
wchar nextChar()
Reads and returns the next UTF16 character, advancing the iterator.
uint04 location(const StringView &original_string) const
Returns the current byte offset within the original string.
StringView string
The remaining portion of the string being iterated.
The primary namespace for the NDEVR SDK.
static constexpr bool IsValid(const Angle< t_type > &value)
Checks whether the given Angle holds a valid value.
uint64_t uint08
-Defines an alias representing an 8 byte, unsigned integer
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
static constexpr bool IsInvalid(const Angle< t_type > &value)
Checks whether the given Angle holds an invalid value.
AlocatingAlignedBuffer< String, sizeof(char *)==4 ? 8 :16 > StringBuffer
A Buffer of String objects using aligned allocation optimized for pointer size.
wchar_t wchar
Allias for wchar_t, a value that represents a character of two bytes in size.
constexpr t_to cast(const Angle< t_from > &value)
Casts an Angle from one backing type to another.
istream & operator>>(istream &in, StringView &string)
Stream extraction operator for reading into an StringView.
static const bool Primitive
Whether this type is a primitive.
static const bool Vector
Whether this type is a vector.
static const bool Float
Whether this type is a floating-point number.
static const bool Enum
Whether this type is an enum.
static const bool Boolean
Whether this type is a boolean.
static const bool Integer
Whether this type is an integer.
static const bool Pointer
Whether this type is a pointer.
static const bool String
Whether this type is a string.
static const bool Buffer
Whether this type is a buffer.
static const uint01 Dimensions
Number of dimensions (0 for non-vector types).
static const bool Number
Whether this type is numeric.
static const bool Unsigned
Whether this type is unsigned.
static constexpr ObjectInfo< char, false, false > VectorSub()
Returns the ObjectInfo for the underlying vector element type.
static const bool Color
Whether this type is a color.
Information about the object.