NeoMutt  2024-04-25-1-g3de005
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 <stddef.h>
32#include <assert.h>
33#include <ctype.h>
34#include <stdbool.h>
35#include "mutt/lib.h"
36#include "helpers.h"
37#include "definition.h"
38#include "mutt_thread.h"
39#include "render.h"
40
48const struct ExpandoRenderData *find_get_number(const struct ExpandoRenderData *rdata,
49 int did, int uid)
50{
51 if (!rdata)
52 return NULL;
53
54 for (; rdata->did != -1; rdata++)
55 {
56 if ((rdata->did == did) && (rdata->uid == uid) && rdata->get_number)
57 {
58 return rdata;
59 }
60 }
61
62 return NULL;
63}
64
72const struct ExpandoRenderData *find_get_string(const struct ExpandoRenderData *rdata,
73 int did, int uid)
74{
75 if (!rdata)
76 return NULL;
77
78 for (; rdata->did != -1; rdata++)
79 {
80 if ((rdata->did == did) && (rdata->uid == uid) && rdata->get_string)
81 {
82 return rdata;
83 }
84 }
85
86 return NULL;
87}
88
95const char *skip_until_ch(const char *start, char terminator)
96{
97 while (*start)
98 {
99 if (*start == terminator)
100 {
101 break;
102 }
103
104 start++;
105 }
106
107 return start;
108}
109
115static bool is_valid_classic_expando(char ch)
116{
117 // NOTE(g0mb4): Maybe rework this?
118 // if special expandos are added this list must be updated!
119 return isalpha(ch) || (ch == ' ') || (ch == '!') || (ch == '(') ||
120 (ch == '*') || (ch == '>') || (ch == '@') || (ch == '[') ||
121 (ch == '^') || (ch == '{') || (ch == '|');
122}
123
129const char *skip_until_classic_expando(const char *start)
130{
131 while (*start && !is_valid_classic_expando(*start))
132 {
133 start++;
134 }
135
136 return start;
137}
138
145const char *skip_classic_expando(const char *str, const struct ExpandoDefinition *defs)
146{
147 assert(str);
148 if (*str == '\0')
149 return str;
150
151 const struct ExpandoDefinition *definitions = defs;
152
153 while (definitions && definitions->short_name)
154 {
155 const bool is_two_char = mutt_str_len(definitions->short_name) == 2;
156 const char *name = definitions->short_name;
157
158 if (is_two_char && (name[0] == *str) && (name[1] == *(str + 1)))
159 {
160 str++;
161 break;
162 }
163
164 definitions++;
165 }
166
167 str++;
168 return str;
169}
170
177void buf_lower_special(struct Buffer *buf)
178{
179 if (!buf || !buf->data)
180 return;
181
182 char *p = buf->data;
183
184 while (*p)
185 {
186 if (*p == MUTT_SPECIAL_INDEX)
187 {
188 p += 2;
189 continue;
190 }
191 else if (*p < MUTT_TREE_MAX)
192 {
193 p++;
194 continue;
195 }
196
197 *p = tolower((unsigned char) *p);
198 p++;
199 }
200}
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:95
const char * skip_classic_expando(const char *str, const struct ExpandoDefinition *defs)
Skip over the text of an Expando.
Definition: helpers.c:145
const char * skip_until_classic_expando(const char *start)
Search through string until we reach an Expando character.
Definition: helpers.c:129
const struct ExpandoRenderData * find_get_number(const struct ExpandoRenderData *rdata, int did, int uid)
Find a get_number() callback function.
Definition: helpers.c:48
const struct ExpandoRenderData * find_get_string(const struct ExpandoRenderData *rdata, int did, int uid)
Find a get_string() callback function.
Definition: helpers.c:72
static bool is_valid_classic_expando(char ch)
Is this a valid Expando character?
Definition: helpers.c:115
void buf_lower_special(struct Buffer *buf)
Convert to lowercase, excluding special characters.
Definition: helpers.c:177
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:490
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.
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
void(* get_string)(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, int max_cols, struct Buffer *buf)
Definition: render.h:65
long(* get_number)(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
Definition: render.h:79
int did
Domain ID.
Definition: render.h:49
int uid
Unique ID.
Definition: render.h:50