ReactOS 0.4.15-dev-7788-g1ad9096
DynamicStrings

Functions

TRIO_STRING_PRIVATE trio_string_tTrioStringAlloc (TRIO_NOARGS)
 
TRIO_STRING_PRIVATE BOOLEAN_T TrioStringGrow TRIO_ARGS2 ((self, delta), trio_string_t *self, size_t delta)
 
TRIO_STRING_PRIVATE BOOLEAN_T TrioStringGrowTo TRIO_ARGS2 ((self, length), trio_string_t *self, size_t length)
 
TRIO_STRING_PUBLIC trio_string_t *trio_string_create TRIO_ARGS1 ((initial_size), int initial_size)
 
TRIO_STRING_PUBLIC void trio_string_destroy TRIO_ARGS1 ((self), trio_string_t *self)
 
TRIO_STRING_PUBLIC char *trio_string_get TRIO_ARGS2 ((self, offset), trio_string_t *self, int offset)
 
TRIO_STRING_PUBLIC void trio_xstring_set TRIO_ARGS2 ((self, buffer), trio_string_t *self, char *buffer)
 
TRIO_STRING_PUBLIC int trio_string_append TRIO_ARGS2 ((self, other), trio_string_t *self, trio_string_t *other)
 
TRIO_STRING_PUBLIC int trio_xstring_append TRIO_ARGS2 ((self, other), trio_string_t *self, TRIO_CONST char *other)
 
TRIO_STRING_PUBLIC int trio_xstring_append_char TRIO_ARGS2 ((self, character), trio_string_t *self, char character)
 
TRIO_STRING_PUBLIC trio_string_t *trio_string_duplicate TRIO_ARGS1 ((other), trio_string_t *other)
 
TRIO_STRING_PUBLIC trio_string_t *trio_xstring_duplicate TRIO_ARGS1 ((other), TRIO_CONST char *other)
 
TRIO_STRING_PUBLIC int trio_string_equal_max TRIO_ARGS3 ((self, max, other), trio_string_t *self, size_t max, trio_string_t *other)
 
TRIO_STRING_PUBLIC int trio_xstring_equal_max TRIO_ARGS3 ((self, max, other), trio_string_t *self, size_t max, TRIO_CONST char *other)
 
TRIO_STRING_PUBLIC size_t trio_string_format_date_max TRIO_ARGS4 ((self, max, format, datetime), trio_string_t *self, size_t max, TRIO_CONST char *format, TRIO_CONST struct tm *datetime)
 
TRIO_STRING_PUBLIC char *trio_string_index TRIO_ARGS2 ((self, character), trio_string_t *self, int character)
 

Detailed Description

Function Documentation

◆ TRIO_ARGS1() [1/4]

TRIO_STRING_PUBLIC trio_string_t *trio_string_create TRIO_ARGS1 ( (initial_size)  ,
int  initial_size 
)

Create a new dynamic string.

Parameters
initial_sizeInitial size of the buffer.
Returns
Newly allocated dynamic string, or NULL if memory allocation failed.

Definition at line 1349 of file triostr.c.

1351{
1352 trio_string_t *self;
1353
1354 self = TrioStringAlloc();
1355 if (self)
1356 {
1357 if (TrioStringGrow(self,
1358 (size_t)((initial_size > 0) ? initial_size : 1)))
1359 {
1360 self->content[0] = (char)0;
1361 self->allocated = initial_size;
1362 }
1363 else
1364 {
1365 trio_string_destroy(self);
1366 self = NULL;
1367 }
1368 }
1369 return self;
1370}
unsigned char
Definition: typeof.h:29
TRIO_STRING_PRIVATE trio_string_t * TrioStringAlloc(TRIO_NOARGS)
Definition: triostr.c:1272
size_t allocated
Definition: triostr.c:102
char * content
Definition: triostr.c:100
#define NULL
Definition: triostr.c:42

◆ TRIO_ARGS1() [2/4]

TRIO_STRING_PUBLIC trio_string_t *trio_xstring_duplicate TRIO_ARGS1 ( (other ,
TRIO_CONST char other 
)

Definition at line 1727 of file triostr.c.

1729{
1730 trio_string_t *self;
1731
1732 assert(other);
1733
1734 self = TrioStringAlloc();
1735 if (self)
1736 {
1737 self->content = TrioDuplicateMax(other, trio_length(other));
1738 if (self->content)
1739 {
1740 self->length = trio_length(self->content);
1741 self->allocated = self->length + 1;
1742 }
1743 else
1744 {
1745 self->length = self->allocated = 0;
1746 }
1747 }
1748 return self;
1749}
#define assert(x)
Definition: debug.h:53
int other
Definition: msacm.c:1376
size_t length
Definition: triostr.c:101

◆ TRIO_ARGS1() [3/4]

TRIO_STRING_PUBLIC trio_string_t *trio_string_duplicate TRIO_ARGS1 ( (other ,
trio_string_t other 
)

Definition at line 1696 of file triostr.c.

1698{
1699 trio_string_t *self;
1700
1701 assert(other);
1702
1703 self = TrioStringAlloc();
1704 if (self)
1705 {
1706 self->content = TrioDuplicateMax(other->content, other->length);
1707 if (self->content)
1708 {
1709 self->length = other->length;
1710 self->allocated = self->length + 1;
1711 }
1712 else
1713 {
1714 self->length = self->allocated = 0;
1715 }
1716 }
1717 return self;
1718}

◆ TRIO_ARGS1() [4/4]

TRIO_STRING_PUBLIC int trio_string_upper TRIO_ARGS1 ( (self)  ,
trio_string_t self 
)

Deallocate the dynamic string and its contents.

Parameters
selfDynamic string

Extract the content.

Parameters
selfDynamic String
Returns
Content of dynamic string.

The content is removed from the dynamic string. This enables destruction of the dynamic string without deallocation of the content.

Definition at line 1381 of file triostr.c.

1383{
1384 assert(self);
1385
1386 if (self)
1387 {
1388 trio_destroy(self->content);
1389 TRIO_FREE(self);
1390 }
1391}
#define TRIO_FREE(x)
Definition: triop.h:77

◆ TRIO_ARGS2() [1/8]

TRIO_STRING_PUBLIC void trio_xstring_set TRIO_ARGS2 ( (self, buffer ,
trio_string_t self,
char buffer 
)

Set the content of the dynamic string.

Parameters
selfDynamic String
bufferThe new content.

Sets the content of the dynamic string to a copy buffer. An existing content will be deallocated first, if necessary.

Remarks
This function will make a copy of buffer. You are responsible for deallocating buffer yourself.

Definition at line 1489 of file triostr.c.

1492{
1493 assert(self);
1494
1495 trio_destroy(self->content);
1496 self->content = trio_duplicate(buffer);
1497}
GLuint buffer
Definition: glext.h:5915

◆ TRIO_ARGS2() [2/8]

TRIO_STRING_PUBLIC int trio_xstring_append_char TRIO_ARGS2 ( (self, character)  ,
trio_string_t self,
char  character 
)

Definition at line 1592 of file triostr.c.

1595{
1596 assert(self);
1597
1598 if ((int)self->length >= trio_string_size(self))
1599 {
1600 if (!TrioStringGrow(self, 0))
1601 goto error;
1602 }
1603 self->content[self->length] = character;
1604 self->length++;
1605 return TRUE;
1606
1607 error:
1608 return FALSE;
1609}
#define error(str)
Definition: mkdosfs.c:1605
#define TRUE
Definition: triostr.c:49
#define FALSE
Definition: triostr.c:48

◆ TRIO_ARGS2() [3/8]

TRIO_STRING_PUBLIC char *trio_string_index_last TRIO_ARGS2 ( (self, character)  ,
trio_string_t self,
int  character 
)

Definition at line 1925 of file triostr.c.

1928{
1929 assert(self);
1930
1931 return trio_index(self->content, character);
1932}

◆ TRIO_ARGS2() [4/8]

TRIO_STRING_PRIVATE BOOLEAN_T TrioStringGrow TRIO_ARGS2 ( (self, delta)  ,
trio_string_t self,
size_t  delta 
)

Definition at line 1295 of file triostr.c.

1298{
1300 char *new_content;
1301 size_t new_size;
1302
1303 new_size = (delta == 0)
1304 ? ( (self->allocated == 0) ? 1 : self->allocated * 2 )
1305 : self->allocated + delta;
1306
1307 new_content = (char *)TRIO_REALLOC(self->content, new_size);
1308 if (new_content)
1309 {
1310 self->content = new_content;
1311 self->allocated = new_size;
1312 status = TRUE;
1313 }
1314 return status;
1315}
Definition: ps.c:97
#define TRIO_REALLOC(x, n)
Definition: triop.h:74
#define BOOLEAN_T
Definition: triostr.c:52

◆ TRIO_ARGS2() [5/8]

TRIO_STRING_PRIVATE BOOLEAN_T TrioStringGrowTo TRIO_ARGS2 ( (self, length ,
trio_string_t self,
size_t  length 
)

Definition at line 1328 of file triostr.c.

1331{
1332 length++; /* Room for terminating zero */
1333 return (self->allocated < length)
1334 ? TrioStringGrow(self, length - self->allocated)
1335 : TRUE;
1336}
GLuint GLsizei GLsizei * length
Definition: glext.h:6040

◆ TRIO_ARGS2() [6/8]

TRIO_STRING_PUBLIC char *trio_string_get TRIO_ARGS2 ( (self, offset ,
trio_string_t self,
int  offset 
)

Get a pointer to the content.

Parameters
selfDynamic string.
offsetOffset into content.
Returns
Pointer to the content.

Offset can be zero, positive, or negative. If offset is zero, then the start of the content will be returned. If offset is positive, then a pointer to offset number of characters from the beginning of the content is returned. If offset is negative, then a pointer to offset number of characters from the ending of the string, starting at the terminating zero, is returned.

Definition at line 1411 of file triostr.c.

1414{
1415 char *result = NULL;
1416
1417 assert(self);
1418
1419 if (self->content != NULL)
1420 {
1421 if (self->length == 0)
1422 {
1423 (void)trio_string_length(self);
1424 }
1425 if (offset >= 0)
1426 {
1427 if (offset > (int)self->length)
1428 {
1429 offset = self->length;
1430 }
1431 }
1432 else
1433 {
1434 offset += self->length + 1;
1435 if (offset < 0)
1436 {
1437 offset = 0;
1438 }
1439 }
1440 result = &(self->content[offset]);
1441 }
1442 return result;
1443}
GLuint64EXT * result
Definition: glext.h:11304
GLintptr offset
Definition: glext.h:5920

◆ TRIO_ARGS2() [7/8]

TRIO_STRING_PUBLIC char *trio_xstring_substring TRIO_ARGS2 ( (self, other ,
trio_string_t self,
TRIO_CONST char other 
)

Definition at line 1565 of file triostr.c.

1568{
1569 size_t length;
1570
1571 assert(self);
1572 assert(other);
1573
1574 length = self->length + trio_length(other);
1575 if (!TrioStringGrowTo(self, length))
1576 goto error;
1577 trio_copy(&self->content[self->length], other);
1578 self->length = length;
1579 return TRUE;
1580
1581 error:
1582 return FALSE;
1583}

◆ TRIO_ARGS2() [8/8]

TRIO_STRING_PUBLIC char *trio_string_substring TRIO_ARGS2 ( (self, other ,
trio_string_t self,
trio_string_t other 
)

Append the second string to the first.

Parameters
selfDynamic string to be modified.
otherDynamic string to copy from.
Returns
Boolean value indicating success or failure.

Search for the first occurrence of second parameter in the first.

Parameters
selfDynamic string to be modified.
otherDynamic string to copy from.
Returns
Boolean value indicating success or failure.

Definition at line 1537 of file triostr.c.

1540{
1541 size_t length;
1542
1543 assert(self);
1544 assert(other);
1545
1546 length = self->length + other->length;
1547 if (!TrioStringGrowTo(self, length))
1548 goto error;
1549 trio_copy(&self->content[self->length], other->content);
1550 self->length = length;
1551 return TRUE;
1552
1553 error:
1554 return FALSE;
1555}

◆ TRIO_ARGS3() [1/2]

TRIO_STRING_PUBLIC int trio_xstring_equal_case_max TRIO_ARGS3 ( (self, max, other ,
trio_string_t self,
size_t  max,
TRIO_CONST char other 
)

Definition at line 1813 of file triostr.c.

1817{
1818 assert(self);
1819 assert(other);
1820
1821 return trio_equal_max(self->content, max, other);
1822}
#define max(a, b)
Definition: svc.c:63

◆ TRIO_ARGS3() [2/2]

TRIO_STRING_PUBLIC int trio_string_equal_case_max TRIO_ARGS3 ( (self, max, other ,
trio_string_t self,
size_t  max,
trio_string_t other 
)

Definition at line 1794 of file triostr.c.

1798{
1799 assert(self);
1800 assert(other);
1801
1802 return trio_equal_max(self->content, max, other->content);
1803}

◆ TRIO_ARGS4()

TRIO_STRING_PUBLIC size_t trio_string_format_date_max TRIO_ARGS4 ( (self, max, format, datetime)  ,
trio_string_t self,
size_t  max,
TRIO_CONST char format,
TRIO_CONST struct tm datetime 
)

Definition at line 1906 of file triostr.c.

1911{
1912 assert(self);
1913
1914 return trio_format_date_max(self->content, max, format, datetime);
1915}
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546

◆ TrioStringAlloc()

Definition at line 1272 of file triostr.c.

1273{
1274 trio_string_t *self;
1275
1276 self = (trio_string_t *)TRIO_MALLOC(sizeof(trio_string_t));
1277 if (self)
1278 {
1279 self->content = NULL;
1280 self->length = 0;
1281 self->allocated = 0;
1282 }
1283 return self;
1284}
#define TRIO_MALLOC(n)
Definition: triop.h:71

Referenced by TRIO_ARGS1().