NeoMutt  2022-04-29-247-gc6aae8
Teaching an old dog new tricks
tag.c File Reference

Notmuch tag functions. More...

#include "config.h"
#include <stddef.h>
#include <ctype.h>
#include "mutt/lib.h"
#include "notmuch/tag.h"
+ Include dependency graph for tag.c:

Go to the source code of this file.


void nm_tag_array_free (struct TagArray *tags)
 Free all memory of a TagArray. More...
struct TagArray nm_tag_str_to_tags (const char *tag_str)
 Converts a comma and/or space-delimited string of tags into an array. More...

Detailed Description

Notmuch tag functions.

  • Austin Ray

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see

Definition in file tag.c.

Function Documentation

◆ nm_tag_array_free()

void nm_tag_array_free ( struct TagArray tags)

Free all memory of a TagArray.

tagsTagArray being cleaned up

Definition at line 39 of file tag.c.

41 ARRAY_FREE(&tags->tags);
42 FREE(&tags->tag_str);
#define ARRAY_FREE(head)
Release all memory.
Definition: array.h:203
#define FREE(x)
Definition: memory.h:43
struct Tags tags
Definition: tag.h:38
char * tag_str
Source string.
Definition: tag.h:39
+ Here is the caller graph for this function:

◆ nm_tag_str_to_tags()

struct TagArray nm_tag_str_to_tags ( const char *  tag_str)

Converts a comma and/or space-delimited string of tags into an array.

tag_strString containing a list of tags, comma- and/or space-delimited
Return values
objArray containing tags represented as strings

Definition at line 50 of file tag.c.

52 char *buf = mutt_str_dup(tag_str);
54 struct TagArray tags = { ARRAY_HEAD_INITIALIZER, buf };
56 char *end = NULL;
57 char *tag = NULL;
59 for (char *p = buf; p && (p[0] != '\0'); p++)
60 {
61 if (!tag && isspace(*p))
62 continue;
63 if (!tag)
64 tag = p; /* begin of the tag */
65 if ((p[0] == ',') || (p[0] == ' '))
66 end = p; /* terminate the tag */
67 else if (p[1] == '\0')
68 end = p + 1; /* end of optstr */
69 if (!tag || !end)
70 continue;
71 if (tag >= end)
72 break;
73 *end = '\0';
75 ARRAY_ADD(&tags.tags, tag);
77 end = NULL;
78 tag = NULL;
79 }
81 return tags;
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition: array.h:155
Static initializer for arrays.
Definition: array.h:57
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:250
Array of Notmuch tags.
Definition: tag.h:37
+ Here is the call graph for this function:
+ Here is the caller graph for this function: