NeoMutt  2024-10-02-34-g9dd811
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
helpers.c
Go to the documentation of this file.
1
30#include "config.h"
31#include <ctype.h>
32#include <stdbool.h>
33#include <stddef.h>
34#include "mutt/lib.h"
35#include "helpers.h"
36#include "definition.h"
37#include "mutt_thread.h"
38#include "render.h"
39
47const struct ExpandoRenderData *find_get_number(const struct ExpandoRenderData *rdata,
48 int did, int uid)
49{
50 if (!rdata)
51 return NULL;
52
53 for (; rdata->did != -1; rdata++)
54 {
55 if ((rdata->did == did) && (rdata->uid == uid) && rdata->get_number)
56 {
57 return rdata;
58 }
59 }
60
61 return NULL;
62}
63
71const struct ExpandoRenderData *find_get_string(const struct ExpandoRenderData *rdata,
72 int did, int uid)
73{
74 if (!rdata)
75 return NULL;
76
77 for (; rdata->did != -1; rdata++)
78 {
79 if ((rdata->did == did) && (rdata->uid == uid) && rdata->get_string)
80 {
81 return rdata;
82 }
83 }
84
85 return NULL;
86}
87
94const char *skip_until_ch(const char *start, char terminator)
95{
96 while (*start)
97 {
98 if (*start == terminator)
99 {
100 break;
101 }
102
103 start++;
104 }
105
106 return start;
107}
108
114static bool is_valid_classic_expando(char ch)
115{
116 // NOTE(g0mb4): Maybe rework this?
117 // if special expandos are added this list must be updated!
118 return isalpha(ch) || (ch == ' ') || (ch == '!') || (ch == '(') ||
119 (ch == '*') || (ch == '>') || (ch == '@') || (ch == '[') ||
120 (ch == '^') || (ch == '{') || (ch == '|');
121}
122
128const char *skip_until_classic_expando(const char *start)
129{
130 while (*start && !is_valid_classic_expando(*start))
131 {
132 start++;
133 }
134
135 return start;
136}
137
144const char *skip_classic_expando(const char *str, const struct ExpandoDefinition *defs)
145{
146 ASSERT(str);
147 if (*str == '\0')
148 return str;
149
150 const struct ExpandoDefinition *def = defs;
151
152 while (def && def->short_name)
153 {
154 const bool is_two_char = mutt_str_len(def->short_name) == 2;
155 const char *name = def->short_name;
156
157 if (is_two_char && (name[0] == *str) && (name[1] == *(str + 1)))
158 {
159 str++;
160 break;
161 }
162
163 def++;
164 }
165
166 str++;
167 return str;
168}
169
176void buf_lower_special(struct Buffer *buf)
177{
178 if (!buf || !buf->data)
179 return;
180
181 char *p = buf->data;
182
183 while (*p)
184 {
185 if (*p == MUTT_SPECIAL_INDEX)
186 {
187 p += 2;
188 continue;
189 }
190 else if (*p < MUTT_TREE_MAX)
191 {
192 p++;
193 continue;
194 }
195
196 *p = tolower((unsigned char) *p);
197 p++;
198 }
199}
Define an Expando format string.
const char * skip_until_ch(const char *start, char terminator)
Search a string for a terminator character.
Definition: helpers.c:94
const char * skip_classic_expando(const char *str, const struct ExpandoDefinition *defs)
Skip over the text of an Expando.
Definition: helpers.c:144
const char * skip_until_classic_expando(const char *start)
Search through string until we reach an Expando character.
Definition: helpers.c:128
const struct ExpandoRenderData * find_get_number(const struct ExpandoRenderData *rdata, int did, int uid)
Find a get_number() callback function.
Definition: helpers.c:47
const struct ExpandoRenderData * find_get_string(const struct ExpandoRenderData *rdata, int did, int uid)
Find a get_string() callback function.
Definition: helpers.c:71
static bool is_valid_classic_expando(char ch)
Is this a valid Expando character?
Definition: helpers.c:114
void buf_lower_special(struct Buffer *buf)
Convert to lowercase, excluding special characters.
Definition: helpers.c:176
Shared code.
Convenience wrapper for the library headers.
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:496
Create/manipulate threading in emails.
@ MUTT_TREE_MAX
Definition: mutt_thread.h:71
@ MUTT_SPECIAL_INDEX
Colour indicator.
Definition: mutt_thread.h:73
Render Expandos using Data.
#define ASSERT(COND)
Definition: signal2.h:58
String manipulation buffer.
Definition: buffer.h:36
char * data
Pointer to data.
Definition: buffer.h:37
Definition of a format string.
Definition: definition.h:52
const char * short_name
Short Expando name, e.g. "n".
Definition: definition.h:53
long(* get_number)(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
Definition: render.h:78
int did
Domain ID.
Definition: render.h:49
void(* get_string)(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
Definition: render.h:64
int uid
Unique ID.
Definition: render.h:50