NeoMutt
2025-12-11-1039-g550ac6
Teaching an old dog new tricks
DOXYGEN
Toggle main menu visibility
Loading...
Searching...
No Matches
tag.c
Go to the documentation of this file.
1
24
30
31
#include "config.h"
32
#include <stddef.h>
33
#include "
mutt/lib.h
"
34
#include "
tag.h
"
35
40
void
nm_tag_array_free
(
struct
NmTags
*
tags
)
41
{
42
ARRAY_FREE
(&
tags
->tags);
43
FREE
(&
tags
->tag_str);
44
}
45
51
struct
NmTags
nm_tag_str_to_tags
(const char *
tag_str
)
52
{
53
char
*buf =
mutt_str_dup
(
tag_str
);
54
55
struct
NmTags
tags
= {
ARRAY_HEAD_INITIALIZER
, buf };
56
57
char
*end = NULL;
58
char
*tag = NULL;
59
60
for
(
char
*p = buf; p && (p[0] !=
'\0'
); p++)
61
{
62
if
(!tag &&
mutt_isspace
(*p))
63
continue
;
64
if
(!tag)
65
tag = p;
/* begin of the tag */
66
if
((p[0] ==
','
) || (p[0] ==
' '
))
67
end = p;
/* terminate the tag */
68
else
if
(p[1] ==
'\0'
)
69
end = p + 1;
/* end of optstr */
70
if
(!tag || !end)
71
continue
;
72
if
(tag >= end)
73
break
;
74
*end =
'\0'
;
75
76
ARRAY_ADD
(&
tags
.tags, tag);
77
78
end = NULL;
79
tag = NULL;
80
}
81
82
return
tags
;
83
}
ARRAY_ADD
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition
array.h:157
ARRAY_FREE
#define ARRAY_FREE(head)
Release all memory.
Definition
array.h:209
ARRAY_HEAD_INITIALIZER
#define ARRAY_HEAD_INITIALIZER
Static initializer for arrays.
Definition
array.h:58
mutt_isspace
bool mutt_isspace(int arg)
Wrapper for isspace(3).
Definition
ctype.c:96
FREE
#define FREE(x)
Free memory and set the pointer to NULL.
Definition
memory.h:68
lib.h
Convenience wrapper for the library headers.
mutt_str_dup
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition
string.c:257
NmTags
Array of Notmuch tags.
Definition
tag.h:36
NmTags::tags
struct StringArray tags
Tags.
Definition
tag.h:37
NmTags::tag_str
char * tag_str
Source string.
Definition
tag.h:38
nm_tag_array_free
void nm_tag_array_free(struct NmTags *tags)
Free all memory of a NmTags.
Definition
tag.c:40
nm_tag_str_to_tags
struct NmTags nm_tag_str_to_tags(const char *tag_str)
Converts a comma and/or space-delimited string of tags into an array.
Definition
tag.c:51
tag.h
Notmuch tag functions.