29#define MCGIDI_MIN(x,y) ( ( (x) < (y) ) ? (x) : (y) )
30#define MCGIDI_SWAP(a,b,type) {type ttttttttt=a;a=b;b=ttttttttt;}
48 p =
static_cast<char*
>(
malloc(b));
49 }
while ( p ==
nullptr );
62 char *p2 = malloc_never_null(len);
79 p = malloc_never_null( s.size_ + 1 );
80 allocated_ = s.size_ + 1;
82 memcpy(p, s.p, size_ + 1);
86 : p(strdup_never_null(s))
95 char* copy = (
char*)
malloc( len + 1);
114 this->
reserve(size_ + s.size_);
126 if (size_ + lens + 1 <= allocated_) {
134 s2.size_ = size_ + lens;
150 if (size_ == allocated_ - 1) {
151 size_t more = (allocated_* 3) / 2;
152 if ( more < 4 ) more = 4;
185 return String(lhs) += rhs;
194 LUPI_THROW(
"MCGIDI::String::substr: pos index out of range");
198 if ( in_length > remain )
201 s.reserve( in_length );
203 memcpy(s.p, p + pos, in_length);
204 s.p[in_length] =
'\0';
215 LUPI_THROW(
"MCGIDI::String::at(): index out_of_range");
222 LUPI_THROW(
"MCGIDI::String::at(): index out_of_range");
232 LUPI_THROW(
"MCGIDI::String::erase: pos index out_of_range");
234 long s2 = (long) size_;
235 long remain = s2 - (long) ( pos - len );
242 if ( remain < 0 ) remain = 0;
245 this->
resize( pos + (
size_t) remain );
256 size_t newlen = size_ + n;
267 LUPI_THROW(
"MCGIDI::String::compare: pos index out of range");
269 if ( len > size_ - pos)
276 r = len < osize ? -1 : ( len == osize ? 0 : +1 );
282 LUPI_THROW(
"MCGIDI::String::compare: pos index out of range");
284 if ( len > size_ - pos)
291 r = len < osize ? -1 : ( len == osize ? 0 : +1 );
297 if (address !=
nullptr && *address !=
nullptr) {
299 long delta = (long) (
sizeof(
char) * n );
300 long sub = delta % 8;
301 if (sub != 0) delta += (8-sub);
306 char* pnew =
static_cast<char*
>(
malloc(n));
312 LUPI_THROW(
"MCGIDI::String::my_realloc out of memory");
318 if (n >= allocated_ ) {
319 this->my_realloc(n + 1, address);
325 this->
resize( n, 0, address );
329 if (n < allocated_ ) {
333 else if (n >= allocated_ ) {
359 const unsigned char *s1 = (
const unsigned char *) p1;
360 const unsigned char *s2 = (
const unsigned char *) p2;
361 unsigned char c1, c2;
365 c1 = (
unsigned char) *s1++;
366 c2 = (
unsigned char) *s2++;
377 while (*str !=
'\0') {
389 char *csrc = (
char *)src;
390 char *cdest = (
char *)dest;
393 char* temp = (
char*)
malloc( n);
396 for (
size_t i=0; i<n; i++)
400 for (
size_t i=0; i<n; i++)
408 while ( n && *s1 && ( *s1 == *s2 ) )
420 return ( *(
unsigned char *)s1 - *(
unsigned char *)s2 );
#define MCGIDI_SWAP(a, b, type)
static const size_type npos
LUPI_HOST_DEVICE int compare(size_type pos, size_type len, const String &str) const
LUPI_HOST_DEVICE bool operator==(const char *) const
LUPI_HOST_DEVICE String & append(const char *str, size_type n)
Append n characters of a string.
LUPI_HOST_DEVICE String & erase(size_type pos, size_type len)
erase len characters at position pos
LUPI_HOST_DEVICE String & operator+=(const String &)
LUPI_HOST_DEVICE void clear()
LUPI_HOST_DEVICE char & at(const size_type i)
LUPI_HOST_DEVICE void swap(String &)
swap contents
LUPI_HOST_DEVICE String & operator=(const char *)
LUPI_HOST_DEVICE String substr(const size_type pos, size_type length) const
LUPI_HOST_DEVICE void resize(size_type n, char **address=nullptr)
LUPI_HOST_DEVICE size_type size() const
size without terminating NUL
LUPI_HOST_DEVICE const char * c_str() const
raw data
LUPI_HOST_DEVICE String()
LUPI_HOST_DEVICE void reserve(size_type n, char **address=nullptr)
LUPI_HOST_DEVICE void clearMemory()
LUPI_HOST_DEVICE ~String()
LUPI_HOST_DEVICE void push_back(char)
Simple C++ string class, useful as replacement for std::string if this cannot be used,...
LUPI_HOST_DEVICE int MCGIDI_strcmp(const char *p1, const char *p2)
LUPI_HOST_DEVICE size_t MCGIDI_strlen(const char *str)
LUPI_HOST_DEVICE String operator+(const String &lhs, const String &rhs)
LUPI_HOST_DEVICE void MCGIDI_memmove(char *dest, const char *src, size_t n)
LUPI_HOST_DEVICE bool operator<(const String &, const String &)
LUPI_HOST_DEVICE int MCGIDI_strncmp(const char *s1, const char *s2, size_t n)