5#ifndef JPP_STRING_HPP_INCLUDED
6#define JPP_STRING_HPP_INCLUDED
8#include <jimcpp/core/engine/jpp_types.hpp>
9#include <jimcpp/core/engine/irrAllocator.hpp>
10#include <jimcpp/core/engine/irrMath.hpp>
34template <
typename T,
typename TAlloc = irrAllocator<T> >
36static size_t multibyteToWString(basic_string<wchar_t>& destination,
const char* source,
u32 sourceSize);
45static eLocaleID locale_current = JPP_LOCALE_ANSI;
46static inline void locale_set ( eLocaleID
id )
52static inline u32 locale_lower (
u32 x )
54 switch ( locale_current )
56 case JPP_LOCALE_GERMAN:
61 return x >=
'A' && x <=
'Z' ? x + 0x20 : x;
65static inline u32 locale_upper (
u32 x )
67 switch ( locale_current )
69 case JPP_LOCALE_GERMAN:
75 return x >=
'a' && x <=
'z' ? x + (
'A' -
'a' ) : x;
91template <
typename T,
typename TAlloc>
102 :
array(0), allocated(1), used(1)
104 array = allocator.allocate(1);
111 :
array(0), allocated(0), used(0)
117 template <
class B,
class A>
119 :
array(0), allocated(0), used(0)
127 :
array(0), allocated(0), used(0)
129 std::ostringstream
tmpbuf;
131 *
this =
tmpbuf.str().data();
137 :
array(0), allocated(0), used(0)
185 :
array(0), allocated(0), used(0)
216 :
array(0), allocated(0), used(0)
264 :
array(0), allocated(0), used(0)
296 :
array(0), allocated(0), used(0)
305 allocated = used =
length+1;
306 array = allocator.allocate(used);
318 :
array(0), allocated(0), used(0)
329 allocator.deallocate(
array);
339 used =
other.size()+1;
342 allocator.deallocate(
array);
344 array = allocator.allocate(used);
348 for (
u32 i=0; i<used; ++i, ++
p)
355 template <
class B,
class A>
358 *
this =
other.data();
371 array = allocator.allocate(1);
379 if ((
void*)c == (
void*)
array)
397 array = allocator.allocate(used);
434 JPP_DEBUG_BREAK_IF(index>=used)
442 JPP_DEBUG_BREAK_IF(index>=used)
469 return used ==
other.used;
483 return (used <
other.used);
490 return !(*
this ==
str);
497 return !(*
this ==
other);
513 return (
size() == 0);
536 std::basic_string<T>
str()
const
543 explicit operator std::basic_string<T> ()
const
572 if (locale_lower(
array[i]) != locale_lower(
other[i]))
575 return used ==
other.used;
608 return used <
other.used;
625 return (i ==
n) || (used ==
other.used);
638 for(i=0; i <
n &&
array[i] &&
str[i]; ++i)
644 return (i ==
n) || (
array[i] == 0 &&
str[i] == 0);
652 if (used + 1 > allocated)
653 reallocate(used + 1);
682 if (used +
len > allocated)
683 reallocate(used +
len);
701 if (
other.size() == 0)
707 if (used +
len > allocated)
708 reallocate(used +
len);
724 if (
other.size() == 0)
733 if (used +
length > allocated)
734 reallocate(used +
length);
760 const u32 end = used+
n-1;
761 for (
u32 i=0; i<used-pos; ++i)
767 for (
u32 i=0; i<
n; ++i)
780 if (count < allocated)
793 for (
u32 i=0; i<used-1; ++i)
812 for (
u32 i=0; i<used-1; ++i)
813 for (
u32 j=0;
j<count; ++
j)
834 for (
u32 i=0; i<used-1; ++i)
837 for (
j=0;
j<count; ++
j)
861 for (
s32 i=(
s32)(used-2); i>=0; --i)
864 for (
j=0;
j<count; ++
j)
898 for (
s32 i=start; i>=0; --i)
917 for (
s32 i=(
s32)used-2; i>=0; --i)
918 for (
u32 j=0;
j<count; ++
j)
944 for (
u32 i=start; i<used-
len; ++i)
980 o.array[i] =
array[i+begin];
985 o.array[i] = locale_lower (
array[i+begin] );
1081 for (
u32 i=0; i<used-1; ++i)
1121 for (
u32 pos = 0; pos < used; ++i, ++pos)
1166 if (used +
len > allocated)
1167 reallocate(used +
len);
1178 while (
ptr != start)
1203 for (
u32 i=0; i<used-1; ++i)
1228 for (
u32 i=0; i<used-1; ++i)
1261 for (
u32 i=0; i<used-1; ++i)
1299 return (*
this =
subString(begin, (end +1) - begin));
1314 if ( i > 0 && (
u32)i < used-2 )
1344 JPP_DEBUG_BREAK_IF(index>=used)
1346 for (
u32 i=index+1; i<used; ++i)
1357 for (
u32 i=0; i<allocated; ++i)
1367 if ( allocated > 0 )
1383 return used > 1 ?
array[used-2] : 0;
1405 template<
class container>
1414 for (
u32 i=0; i<used; ++i)
1458 if (allocated < used)
1496static inline size_t multibyteToWString(basic_string<wchar_t>& destination,
const char* source)
1498 const u32 s = source ? (
u32)strlen(source) : 0;
1499 return multibyteToWString(destination, source, s);
1508#if defined(_MSC_VER)
1509#pragma warning(push)
1510#pragma warning(disable: 4996)
1513#if defined(_MSC_VER)
Axis aligned bounding box in 3d dimensional space.
Definition aabbox3d.hpp:22
Self reallocating template array (like stl vector) with additional features.
Definition irrArray.hpp:23
Very simple string class with some useful features.
Definition irrString.hpp:93
basic_string< T, TAlloc > & replace(T toReplace, T replaceWith)
Replaces all characters of a special type with another one.
Definition irrString.hpp:1079
bool operator!=(const T *const str) const
Inequality operator.
Definition irrString.hpp:488
basic_string< T, TAlloc > & append(const basic_string< T, TAlloc > &other, u32 length)
Appends a string of the length l to this string.
Definition irrString.hpp:722
basic_string< T, TAlloc > & append(const T *const other, u32 length=0xffffffff)
Appends a char string to this string.
Definition irrString.hpp:667
basic_string< T, TAlloc > & removeChars(const basic_string< T, TAlloc > &characters)
Removes characters from a string.
Definition irrString.hpp:1254
T & operator[](const u32 index)
Direct access operator.
Definition irrString.hpp:432
s32 findFirstCharNotInList(const B *const c, u32 count=1) const
Finds first position of a character not in a given list.
Definition irrString.hpp:829
bool operator!=(const basic_string< T, TAlloc > &other) const
Inequality operator.
Definition irrString.hpp:495
basic_string< T, TAlloc > & erase(u32 index)
Erases a character from the string.
Definition irrString.hpp:1342
s32 findLastChar(const T *const c, u32 count=1) const
finds last occurrence of a character of a list in string
Definition irrString.hpp:912
basic_string(const B *const c)
Constructor for Unicode and ASCII strings.
Definition irrString.hpp:317
basic_string(unsigned int number)
Constructs a string from an unsigned int.
Definition irrString.hpp:184
bool equals_substring_ignore_case(const basic_string< T, TAlloc > &other, const s32 sourcePos=0) const
Compares the strings ignoring case.
Definition irrString.hpp:582
u32 split(container &ret, const T *const delimiter, u32 countDelimiters=1, bool ignoreEmptyTokens=true, bool keepSeparators=false) const
Split string into parts (tokens).
Definition irrString.hpp:1406
void reserve(u32 count)
Reserves some memory.
Definition irrString.hpp:778
~basic_string()
Destructor.
Definition irrString.hpp:327
T lastChar() const
gets the last char of a string or null
Definition irrString.hpp:1381
basic_string< T, TAlloc > operator+(const basic_string< T, TAlloc > &other) const
Append operator for other strings.
Definition irrString.hpp:411
basic_string()
Default constructor.
Definition irrString.hpp:101
basic_string< T > subString(u32 begin, s32 length, bool make_lower=false) const
Returns a substring.
Definition irrString.hpp:964
bool operator==(const T *const str) const
Equality operator.
Definition irrString.hpp:448
basic_string(const double number)
Constructs a string from a float.
Definition irrString.hpp:126
basic_string< T, TAlloc > & trim(const basic_string< T, TAlloc > &whitespace=" \t\n\r")
Trims the string.
Definition irrString.hpp:1290
basic_string(long number)
Constructs a string from a long.
Definition irrString.hpp:215
basic_string< T, TAlloc > & eraseTrailingFloatZeros(char decimalPoint='.')
Erase 0's at the end when a string ends with a floating point number.
Definition irrString.hpp:1311
bool operator<(const basic_string< T, TAlloc > &other) const
Is smaller comparator.
Definition irrString.hpp:474
s32 findFirst(T c) const
finds first occurrence of character in string
Definition irrString.hpp:791
basic_string(const B *const c, u32 length)
Constructor for copying a string from a pointer with a given length.
Definition irrString.hpp:295
s32 findNext(T c, u32 startPos) const
finds next occurrence of character in string
Definition irrString.hpp:880
basic_string< T, TAlloc > operator+(const B *const c) const
Append operator for strings, ASCII and Unicode.
Definition irrString.hpp:422
basic_string(int number)
Constructs a string from an int.
Definition irrString.hpp:136
basic_string(const basic_string< T, TAlloc > &other)
Constructor.
Definition irrString.hpp:110
friend size_t multibyteToWString(basic_string< wchar_t > &destination, const char *source, u32 sourceSize)
Internally used by the other multibyteToWString functions.
Definition irrString.hpp:1503
basic_string< T, TAlloc > & operator=(const B *const c)
Assignment operator for strings, ASCII and Unicode.
Definition irrString.hpp:365
s32 findFirstChar(const T *const c, u32 count=1) const
finds first occurrence of a character of a list in string
Definition irrString.hpp:807
s32 findLastCharNotInList(const B *const c, u32 count=1) const
Finds last position of a character not in a given list.
Definition irrString.hpp:856
const T * data() const
Returns character string.
Definition irrString.hpp:528
s32 findLast(T c, s32 start=-1) const
finds last occurrence of character in string
Definition irrString.hpp:895
bool lower_ignore_case(const basic_string< T, TAlloc > &other) const
Compares the strings ignoring case.
Definition irrString.hpp:599
bool equals_ignore_case(const basic_string< T, TAlloc > &other) const
Compares the strings ignoring case.
Definition irrString.hpp:569
basic_string< T, TAlloc > & operator=(const basic_string< B, A > &other)
Assignment operator for other string types.
Definition irrString.hpp:356
bool equalsn(const basic_string< T, TAlloc > &other, u32 n) const
compares the first n characters of the strings
Definition irrString.hpp:616
basic_string< T, TAlloc > & operator=(const basic_string< T, TAlloc > &other)
Assignment operator.
Definition irrString.hpp:334
bool empty() const
Definition irrString.hpp:511
s32 find(const B *const str, const u32 start=0) const
finds another string in this string
Definition irrString.hpp:932
basic_string< T, TAlloc > & replace(const basic_string< T, TAlloc > &toReplace, const basic_string< T, TAlloc > &replaceWith)
Replaces all instances of a string with another one.
Definition irrString.hpp:1091
std::basic_string< T > str() const
Returns std::string or std::wstring. The traits_type and allocator_type of the returned std::basic_st...
Definition irrString.hpp:536
basic_string< T, TAlloc > & make_lower()
Makes the string lower case.
Definition irrString.hpp:549
basic_string(unsigned long number)
Constructs a string from an unsigned long.
Definition irrString.hpp:263
basic_string< T, TAlloc > & append(T character)
Appends a character to this string.
Definition irrString.hpp:650
u32 size() const
Returns length of the string's content.
Definition irrString.hpp:504
basic_string< T, TAlloc > & append(const basic_string< T, TAlloc > &other)
Appends a string to this string.
Definition irrString.hpp:699
bool operator==(const basic_string< T, TAlloc > &other) const
Equality operator.
Definition irrString.hpp:463
basic_string< T, TAlloc > & make_upper()
Makes the string upper case.
Definition irrString.hpp:558
operator std::basic_string< T >() const
Returns std::string or std::wstring. The traits_type and allocator_type of the returned std::basic_st...
Definition irrString.hpp:543
bool equalsn(const T *const str, u32 n) const
compares the first n characters of the strings
Definition irrString.hpp:633
basic_string< T, TAlloc > & operator+=(T c)
Appends a character to this string.
Definition irrString.hpp:997
basic_string< T, TAlloc > & insert(u32 pos, const char *s, u32 n)
Insert a certain amount of characters into the string before the given index.
Definition irrString.hpp:753
basic_string< T, TAlloc > & validate()
verify the existing string.
Definition irrString.hpp:1354
basic_string< T, TAlloc > & remove(T c)
Removes characters from a string.
Definition irrString.hpp:1199
basic_string(const basic_string< B, A > &other)
Constructor from other string types.
Definition irrString.hpp:118
basic_string< T, TAlloc > & remove(const basic_string< T, TAlloc > &toRemove)
Removes a string from the string.
Definition irrString.hpp:1221
Basic classes such as vectors, planes, arrays, lists, and so on can be found in this namespace.
Definition vector3d.hpp:13
JIMCPP_API void wcharToUtf8(const wchar_t *in, char *out, const u64 len)
Convert this wchar string to utf-8.
JIMCPP_API void utf8ToWchar(const char *in, wchar_t *out, const u64 len)
Convert this utf-8-encoded string to the platform's wchar.
const T clamp(const T &value, const T &low, const T &high)
clamps a value between low and high
Definition irrMath.hpp:164
s32 isdigit(s32 c)
some standard function ( to remove dependencies )
Definition coreutil.hpp:197
signed int s32
32 bit signed variable.
Definition irrTypes.hpp:72
unsigned int u32
32 bit unsigned variable.
Definition irrTypes.hpp:64
char c8
8 bit character variable.
Definition irrTypes.hpp:37