34#include <NDEVR/Buffer.h>
35#include <NDEVR/StringStream.h>
68 class String :
public Buffer<char, uint04, ObjectAllocator<true>, BufferAllocator<char, uint04, true>>
88 template<std::
size_t N>
96 template<std::
size_t N>
131 template<
class t_type>
142 template <
class t_type>
154 template<
class t_type>
549 if (value[i] != (*
this)[i])
558 if (value[i] != (*
this)[i])
561 return value[
size()] ==
'\0';
563 template<std::
size_t t_size>
566 if (t_size <=
size())
568 if (
string[
size()] !=
'\0')
570 return memcmp(
string,
begin(),
sizeof(
char) *
size()) == 0;
577 if (value[i] != (*
this)[i])
580 return value[
size()] !=
'\0';
582 template<std::
size_t t_size>
585 if (t_size <=
size())
587 if (
string[
size()] !=
'\0')
589 return memcmp(
string,
begin(),
sizeof(
char) *
size()) != 0;
597 if (value[i] != (*
this)[i])
676 template<
class t_
object>
677 static typename std::enable_if<ObjectInfo<t_object>::Integer,
String>::type
ToHex(t_object value)
682 for (
uint04 i = 0; i < byte_size; i++)
685 hex[2 * (byte_size - i - 1) + 0] = local_hex[0];
686 hex[2 * (byte_size - i - 1) + 1] = local_hex[1];
677 static typename std::enable_if<ObjectInfo<t_object>::Integer,
String>::type
ToHex(t_object value) {
…}
696 template<
class t_
object,
class t_allocator,
class t_buff>
703 hex +=
ToHex(values[i]);
718 hex +=
ToHex(values[i]);
727 template<u
int01 t_size,
class t_type>
732 for (
uint01 i = 0; i < t_size; i++)
734 hex +=
ToHex(values[i]);
751 const char* n_value = value;
752 for (; *n_value; ++n_value)
767 const wchar* n_value = value;
768 for (; *n_value; ++n_value)
774 else if (*n_value < 0x800)
780 uint04 cp = (*n_value << 16);
792#pragma warning( disable : 4307)
803 uint08 hash_value = 5381U;
804 for (
const char* n_value = value; *n_value; n_value++)
806 hash_value = ((hash_value << 5) + hash_value) + cast<uint08>(*n_value);
812 static void BadCharHeuristic(
const char* str,
uint04 size,
sint04 badchar[256],
bool ignore_case);
813 static uint04 Search(
const char* txt,
const char* pat,
uint04 size_m,
uint04 size_n,
bool ignore_case);
68 class String :
public Buffer<char, uint04, ObjectAllocator<true>, BufferAllocator<char, uint04, true>> {
…};
838 return std::move(v1);
843 return std::move(v1);
849 return std::move(v1);
855 return std::move(v1);
875 template<
size_t t_size>
879 return std::move(v1);
881 template<
size_t t_size>
894 template<
size_t t_size>
901 template<
size_t t_size>
911 template<
size_t t_size>
920 template<
size_t t_size>
926 s.
addAll((
char*)v1, size);
933 return static_cast<t_to
>(value.
getAs<t_to>());
936 struct ObjectInfo<String, false, true>
938 static const uint01 Dimensions = 0;
939 static const bool Vector =
false;
940 static const bool Buffer =
true;
941 static const bool Primitive =
false;
942 static const bool Pointer =
false;
943 static const bool Unsigned =
false;
944 static const bool Float =
false;
945 static const bool Integer =
false;
946 static const bool Number =
false;
947 static const bool Enum =
false;
948 static const bool String =
true;
949 static const bool Color =
false;
950 static const bool Boolean =
false;
951 static constexpr ObjectInfo<char, false, false> VectorSub() {
return ObjectInfo<char, false, false>(); }
958 return value.
size() == 0;
966 struct hash<
NDEVR::String>
968 std::size_t operator()(
const NDEVR::String& s)
const noexcept
970 return static_cast<size_t>(s.hash());
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:56
Buffer & operator=(const Buffer &buffer)
Definition Buffer.hpp:932
void add(t_type &&object)
Adds object to the end of the buffer.
Definition Buffer.hpp:186
constexpr uint04 size() const
Definition Buffer.hpp:823
void addAll(const Buffer< t_type, t_other_index_type, t_other_memory_allocator, t_other_memory_manager > &buffer)
Definition Buffer.hpp:243
decltype(auto) end()
Definition Buffer.hpp:507
void setSize(t_index_type new_size)
Definition Buffer.hpp:803
t_index_type indexOf(const t_type &element) const
Definition Buffer.hpp:559
void ensureCapacity(t_index_type new_capacity, bool ensure_not_greater=false, bool ensure_not_less=true)
Definition Buffer.hpp:519
decltype(auto) begin()
Definition Buffer.hpp:402
uint04 count(const char &element) const
Definition Buffer.hpp:503
Definition MemoryManager.h:261
The core String class for the NDEVR API.
Definition String.h:69
String(uint04 size, const char &value)
String Constructor creates a string of a size and fills it with a character.
Definition String.h:122
const char * c_str() const
Used to access the raw memory of this string.
uint08 hashLower() const
Creates a simple, quick hash of the object. See hash(const char* value) for details of the implementa...
uint04 indexOf(const char &sub_string) const
Given a substring specified by the input, returns the first index of that string, if it exists.
Definition String.h:204
String predictNextStringIncrement() const
Looks in the string for key markers that might be an index, and attempts to increment the index....
static String UTF16toUTF8(const wchar *unicode, uint04 &advance)
bool addUTF16CharAsUTF8(const wchar *unicode, uint04 &advance)
Converts a single unicode character at advance into UTF8 and appends it to the end of the String.
bool operator<(const String &value) const
bool hasSubString(const String &sub_string, bool ignore_case=false) const
Tests if this String contains the specified substring.
static bool AlphaNumericCompare(const String &left, const String &right)
Compares two strings given their alpha-numeric determined value.
uint04 fromHex() const
Converts a hex value into an unsigned 4 byte number.
String & addWhiteSpace(uint04 desired_string_size, uint04 desired_right_alignment_location=0, char whitespace=' ')
Used for formatting, will, if necessary, add white space so that the string becomes a certain length....
String & removeNonAlphaNumeric(bool remove_tab=true, bool remove_space=true, bool remove_new_line=true, bool remove_r=true, bool remove_numbers=false)
Removes any characters that aren't numbers or letters with other options available.
bool isNumeric() const
Checks to see if the string is a numeric string.
void splitString(const Buffer< char > &delimiter, Buffer< String, uint04, ObjectAllocator< false > > &strings, bool preserve_empty=true) const
Given multiple delimiter, breaks the string into subsections, and APPENDS each substring to the given...
static constexpr uint08 hash(const char *value)
constexpr method to hash a value. Also provides the hashing method used throughout the API to hash st...
Definition String.h:801
bool operator==(const char *const value) const
Definition String.h:554
static String ToHex(char value)
Converts the memory of the given object into a hexidecimal string.
static constexpr uint04 str_len(const char *value)
constexpr method to get the length of a null-terminated string at compile time
Definition String.h:749
static String ConvertToCharString(uint04 number)
Converts a number into a char string. For example 0 will become 'A' and 27 will become 'AA'.
String(const t_type &value)
String Constructor that creates a string based off an object. To use this function an object must hav...
Definition String.h:132
String shortenString(uint04 size) const
Shortans the string to the max size provided. If string is longer, searches for an ideal place to ins...
String & formatNumberString(bool add_comma, uint04 decimals)
For a string representing a number, makes the decimals equal to the the provided value and adds comma...
size_t operator()() const
Definition String.h:613
String(const char *const string, uint04 size)
String Constructor char arrays when the size is known. Slightly faster than iterating over a null-ter...
String & operator=(String &&value) noexcept
Definition String.h:538
static wchar UTF8toUTF16(const char *utf8, uint04 &advance)
Converts a unicode null terminated string of chars into a UTF16 wchar and increments advance by the a...
uint04 indexOf(const char *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.
String substr(uint04 start, uint04 end) const
Creates a substring from a given start position, to the given end position, non-inclusive of the end ...
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 isSameNoCase(const String &s) const
Checks whether two strings match in a case-insensitive way.
static String ToHex(const String &values)
Converts a string of any type of data (assumed to be binary) into a hex representation.
Definition String.h:712
bool operator==(const String &value) const
Definition String.h:543
bool hasSubString(const char *sub_string, bool ignore_case=false) const
Tests if this String contains the specified substring.
String()
Constructor used to create an empty String*.
String(const String &string)
Copy Constructor.
bool operator!=(const String &value) const
Definition String.h:591
String(String &&string) noexcept
Move contructor (No new memory allocation).
String & formatAsTitleString()
Formats the string to be a title, capitalizing important characters and replacing underscores with sp...
void addWChar(const wchar &object)
Converts a single unicode character UTF16 character into one or more UTF8 characters and appends them...
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.
bool operator==(const char(&string)[t_size])
Definition String.h:564
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.
Definition String.h:213
void addUTF16AsUTF8(const wchar *unicode)
Converts a unicode null terminated string of UTF16 wchars into UTF8 and appends it to the end of the ...
String(const char *string)
String Constructor for null terminated array of chars.
Definition String.h:106
static constexpr uint04 str_len(const wchar *value)
constexpr method to get the UTF8 length of a null-terminated string at compile time
Definition String.h:764
String & trimWhiteSpace()
Trims any white space (tabs, spaces, etc) from the beginning and end of the string.
String substr(uint04 start) const
Creates a substring from a given start position, to the end of the string.
t_type getAs() const
Converts a string into an object. To use this function an object must have overwritten StringStream<t...
Definition String.h:143
String & replace(const String &sub_string, const String &replace_sub_string, bool ignore_case=false)
Replaces ALL instances of a given substring with the provided replacement.
String(const char(&string)[N])
String Constructor for static char arrays.
Definition String.h:89
String & formatNumberString(bool add_comma, uint04 min_decimals, uint04 max_decimals, uint04 min_digits, char decimal='.', char comma=',')
Modifies the contents of this string, that represents a given number using the provided rules.
String & formatNumberString(uint04 decimals)
For a string representing a number, makes the decimals equal to the the provided value Example: Strin...
uint04 indexOf(const String &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.
String insertNewLines(uint04 max_line_size) const
Finds key areas to insert new lines such that the rows are at most, the length provided.
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.
static String ToHex(const Buffer< t_object, t_allocator, t_buff > &values)
Converts a buffer of objects into a hexidecimal string.
Definition String.h:697
String(const wchar(&string)[N])
String Constructor for static wchar arrays of UTF16 data.
Definition String.h:97
static String ToHex(uint01 value)
Converts the memory of the given object into a hexidecimal string.
Buffer< String, uint04, ObjectAllocator< false > > splitString(const Buffer< char > &delimiter, bool preserve_empty=true) const
Given multiple delimiter, breaks the string into subsections, returning an array of each subsection....
String & operator=(const String &value)
Definition String.h:532
static bool IsWhiteSpace(char s)
Checks whether a given character is a whitespace character or not.
String & replace(const Buffer< String, uint04, ObjectAllocator< false > > &sub_string, const Buffer< String, uint04, ObjectAllocator< false > > &replace_sub_string, bool ignore_case=false)
Replaces ALL instances of the given substrings with the provided replacements. This allows safe repla...
String & removeNonNumeric()
Removes anything that is not a number or decimal ('0'-'9' or .)
String toUpper() const
changes all lower case characters into upper case characters.
uint08 hashUpper() const
Creates a simple, quick hash of the object. See hash(const char* value) for details of the implementa...
static String ToHex(const Vector< t_size, t_type > &values)
Converts a vector into a hex representation.
Definition String.h:728
bool operator!=(const char *const value) const
Definition String.h:573
bool matchesWildcard(const String &pattern) const
Checks whether two strings match allowing '' to be used as a wildcard pattern. For example,...
String & append(const String &string)
Appends a string to the back of this string.
static TranslatedString DisplayString(const t_type &value)
Converts an object into a TranslatedString. To use this function an object must have overwritten Stri...
Definition TranslatedString.h:54
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.
Definition String.h:224
bool operator!=(const char(&string)[t_size])
Definition String.h:583
static String NumberString(fltp08 value, bool add_comma, uint04 min_decimals, uint04 max_decimals, uint04 min_digits, char decimal='.', char comma=',')
Creates a string from a given number using the provided rules.
uint08 hash() const
Creates a simple, quick hash of the object. See hash(const char* value) for details of the implementa...
bool operator>(const String &value) const
String toLower() const
changes all upper case characters into lower case characters.
void splitString(char delimiter, Buffer< String, uint04, ObjectAllocator< false > > &strings, bool preserve_empty=true) const
Given multiple delimiter, breaks the string into subsections, and APPENDS each substring to the given...
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.
bool endsWith(const String &s, bool ignore_case=false) const
Tests if this String ends with the specified suffix.
Buffer< String, uint04, ObjectAllocator< false > > splitString(char delimiter, bool preserve_empty=true) const
Given a delimiter, breaks the string into subsections, returning an array of each subsection....
static std::enable_if< ObjectInfo< t_object >::Integer, String >::type ToHex(t_object value)
Converts the memory of the given object into a hexidecimal string.
Definition String.h:677
bool beginsWith(const String &s, bool ignore_case=false) const
Tests if this String starts with the specified prefix.
static void toString(const t_type &value, String &string)
Logic for converting an object to an NDEVR API String allowing it to be used automatically with the S...
static void fromString(const String &string, t_type &value)
Logic for converting an object from an NDEVR API String allowing it to be used automatically with get...
Any text displayed to the user should be defined as a TranslatedString which allows the program to lo...
Definition TranslatedString.h:13
A fixed-size array with better performance compared to dynamic containers.
Definition Vector.hpp:60
int32_t sint04
-Defines an alias representing a 4 byte, signed integer. -Can represent exact integer values -2147483...
Definition BaseValues.hpp:64
constexpr bool IsInvalid(const t_type &value)
Query if 'value' is valid or invalid. Invalid values should return invalid if used for calculations o...
Definition BaseFunctions.hpp:170
bool operator==(const char(&v1)[t_size], const String &v2)
Definition String.h:912
wchar_t wchar
Allias for wchar_t, a value that represents a character of two bytes in size.
Definition BaseValues.hpp:155
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:80
constexpr t_to rcast(t_from value)
Casts the given value. Is equivalent to reinterpret_cast except allows for the option of special case...
Definition BaseValues.hpp:403
String operator+(const String &string_a, const String &string_b)
Definition String.h:827
String & operator+=(String &string, const String &value)
Definition String.h:889
uint64_t uint08
-Defines an alias representing an 8 byte, unsigned integer
Definition BaseValues.hpp:106
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:96
constexpr t_to cast(const Angle< t_from > &value)
Definition Angle.h:375
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:149
istream & operator>>(istream &in, NDEVR::String &string)
ostream & operator<<(ostream &in, const NDEVR::String &string)
Defines for a given type (such as sint04, fltp08, UUID, etc) a maximum, minimum, and reserved 'invali...
Definition BaseValues.hpp:233
Iterates over a UTF8 encoded string and returns the values as UTF16.
Definition String.h:819
UTF8Iterator(const String &string)
const String & string
Definition String.h:823
uint04 m_position
Definition String.h:824