NeoMutt  2024-03-23-147-g885fbc
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
tag.c File Reference

Notmuch tag functions. More...

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

Go to the source code of this file.

Functions

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

Detailed Description

Notmuch tag functions.

Authors
  • Austin Ray
  • Richard Russon

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 http://www.gnu.org/licenses/.

Definition in file tag.c.

Function Documentation

◆ nm_tag_array_free()

void nm_tag_array_free ( struct NmTags tags)

Free all memory of a NmTags.

Parameters
tagsNmTags being cleaned up

Definition at line 40 of file tag.c.

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

◆ 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.

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

Definition at line 51 of file tag.c.

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 && 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}
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition: array.h:156
#define ARRAY_HEAD_INITIALIZER
Static initializer for arrays.
Definition: array.h:58
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:253
Array of Notmuch tags.
Definition: tag.h:38
+ Here is the call graph for this function:
+ Here is the caller graph for this function: