static PyObject* Package_get_groups(PackageObject* self) {
const char* s = pakfire_package_get_groups(self->package);
- PyObject* list = PyList_New(0);
-
- char** groups = pakfire_split_string(s, ',');
- char* group;
-
- while ((group = *groups++) != NULL) {
- PyObject* item = PyUnicode_FromString(group);
- PyList_Append(list, item);
- free(group);
-
- Py_DECREF(item);
- }
-
- free(groups);
-
- return list;
+ return PyUnicode_FromString(s);
}
static int Package_set_groups(PackageObject* self, PyObject* value) {
#include <pakfire/types.h>
-char** pakfire_split_string(const char* s, char delim);
-
char* pakfire_generate_uuid();
#ifdef PAKFIRE_PRIVATE
char* pakfire_unquote_in_place(char* s);
int pakfire_string_partition(const char* s, const char* delim, char** s1, char** s2);
char* pakfire_string_replace(const char* s, const char* pattern, const char* repl);
+char** pakfire_split_string(const char* s, char delim);
char* pakfire_format_size(double size);
char* pakfire_format_date(time_t t);
return result;
}
+char** pakfire_split_string(const char* s, char delim) {
+ // Copy string to stack and count spaces
+ char buffer[strlen(s) + 2];
+
+ size_t count = 1;
+ for (unsigned int i = 0; i < strlen(s) + 1; i++) {
+ buffer[i] = s[i];
+
+ if (s[i] == delim) {
+ buffer[i] = '\0';
+ count++;
+ }
+ }
+
+ // Allocate an array of sufficient size
+ char** ret = malloc(sizeof(*ret) * (count + 1));
+
+ // Copy strings to heap one by one
+ unsigned int i = 0;
+ char* p = buffer;
+ while (*p) {
+ ret[i++] = strdup(p);
+
+ // Move pointer to the next string
+ p += strlen(p) + 1;
+ }
+
+ // Terminate array
+ ret[count] = NULL;
+
+ return ret;
+}
+
char* pakfire_format_size(double size) {
char string[STRING_SIZE];
const char* units[] = {" ", "k", "M", "G", "T", NULL};
return 0;
}
-PAKFIRE_EXPORT char** pakfire_split_string(const char* s, char delim) {
- // Copy string to stack and count spaces
- char buffer[strlen(s) + 2];
-
- size_t count = 1;
- for (unsigned int i = 0; i < strlen(s) + 1; i++) {
- buffer[i] = s[i];
-
- if (s[i] == delim) {
- buffer[i] = '\0';
- count++;
- }
- }
-
- // Allocate an array of sufficient size
- char** ret = malloc(sizeof(*ret) * (count + 1));
-
- // Copy strings to heap one by one
- unsigned int i = 0;
- char* p = buffer;
- while (*p) {
- ret[i++] = strdup(p);
-
- // Move pointer to the next string
- p += strlen(p) + 1;
- }
-
- // Terminate array
- ret[count] = NULL;
-
- return ret;
-}
-
PAKFIRE_EXPORT char* pakfire_generate_uuid() {
uuid_t uuid;