Welcome to mirror list, hosted at ThFree Co, Russian Federation.

strings.c « base « src - github.com/windirstat/premake-4.x-stable.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7862b683147b283ac8525d55d3612896ae7b3f63 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/**
 * \file   strings.c
 * \brief  A dynamic array of C strings.
 * \author Copyright (c) 2002-2008 Jason Perkins and the Premake project
 */

#include <stdlib.h>
#include "premake.h"
#include "strings.h"
#include "base/array.h"

DEFINE_CLASS(Strings)
{
	Array contents;
};



/**
 * Create a new dynamic array of C strings.
 * \returns A new string array.
 */
Strings strings_create()
{
	Strings strs = ALLOC_CLASS(Strings);
	strs->contents = array_create();
	return strs;
}


/**
 * Destroy a strings array and free the associated memory.
 * \param   strs  The string array to destroy.
 */
void strings_destroy(Strings strs)
{
	array_destroy(strs->contents);
	free(strs);
}


/**
 * Add a new item to the end of an array of strings.
 * \param   strs  The array of strings.
 * \param   item  The C string item to add.
 */
void strings_add(Strings strs, const char* item)
{
	array_add(strs->contents, (void*)item);
}


/**
 * Append the contents of one string vector to another.
 * \param   dest    The destination vector.
 * \param   src     The source vector.
 */
void strings_append(Strings dest, Strings src)
{
	array_append(dest->contents, src->contents);
}


/**
 * Retrieve an C string item from an array of strings.
 * \param   strs   The string array to query.
 * \param   index  The index of the item to retrieve.
 * \returns A pointer to the C string item.
 */
const char* strings_item(Strings strs, int index)
{
	return (const char*)array_item(strs->contents, index);
}


/**
 * Set the value at a particular index of the array.
 * \param   strs   The string array.
 * \param   index  The index of the item to set.
 * \param   item   The new item.
 */
void strings_set(Strings strs, int index, const char* item)
{
	array_set(strs->contents, index, (void*)item);
}


/**
 * Get the number of items in the string array.
 * \param   strs   The string array to query.
 * \returns The number elements currently in the array.
 */
int strings_size(Strings strs)
{
	return array_size(strs->contents);
}