NeoMutt  2024-04-25-100-gcb3684
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
helpers.h File Reference

Shared code. More...

+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

const char * skip_classic_expando (const char *str, const struct ExpandoDefinition *defs)
 Skip over the text of an Expando.
 
const char * skip_until_ch (const char *start, char terminator)
 Search a string for a terminator character.
 
const char * skip_until_classic_expando (const char *start)
 Search through string until we reach an Expando character.
 
const struct ExpandoRenderDatafind_get_number (const struct ExpandoRenderData *rdata, int did, int uid)
 Find a get_number() callback function.
 
const struct ExpandoRenderDatafind_get_string (const struct ExpandoRenderData *rdata, int did, int uid)
 Find a get_string() callback function.
 
void buf_lower_special (struct Buffer *buf)
 Convert to lowercase, excluding special characters.
 

Detailed Description

Shared code.

Authors
  • Tóth János
  • 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 helpers.h.

Function Documentation

◆ skip_classic_expando()

const char * skip_classic_expando ( const char *  str,
const struct ExpandoDefinition defs 
)

Skip over the text of an Expando.

Parameters
strStarting place
defsExpando definitions
Return values
ptrCharacter after Expando, or end-of-string

Definition at line 144 of file helpers.c.

145{
146 ASSERT(str);
147 if (*str == '\0')
148 return str;
149
150 const struct ExpandoDefinition *definitions = defs;
151
152 while (definitions && definitions->short_name)
153 {
154 const bool is_two_char = mutt_str_len(definitions->short_name) == 2;
155 const char *name = definitions->short_name;
156
157 if (is_two_char && (name[0] == *str) && (name[1] == *(str + 1)))
158 {
159 str++;
160 break;
161 }
162
163 definitions++;
164 }
165
166 str++;
167 return str;
168}
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:496
#define ASSERT(COND)
Definition: signal2.h:58
Definition of a format string.
Definition: definition.h:52
const char * short_name
Short Expando name, e.g. "n".
Definition: definition.h:53
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ skip_until_ch()

const char * skip_until_ch ( const char *  start,
char  terminator 
)

Search a string for a terminator character.

Parameters
startStart of string
terminatorCharacter to find
Return values
ptrPosition of terminator character, or end-of-string

Definition at line 94 of file helpers.c.

95{
96 while (*start)
97 {
98 if (*start == terminator)
99 {
100 break;
101 }
102
103 start++;
104 }
105
106 return start;
107}
+ Here is the caller graph for this function:

◆ skip_until_classic_expando()

const char * skip_until_classic_expando ( const char *  start)

Search through string until we reach an Expando character.

Parameters
startWhere to start looking
Return values
ptrMatch, or end-of-string

Definition at line 128 of file helpers.c.

129{
130 while (*start && !is_valid_classic_expando(*start))
131 {
132 start++;
133 }
134
135 return start;
136}
static bool is_valid_classic_expando(char ch)
Is this a valid Expando character?
Definition: helpers.c:114
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ find_get_number()

const struct ExpandoRenderData * find_get_number ( const struct ExpandoRenderData rdata,
int  did,
int  uid 
)

Find a get_number() callback function.

Parameters
rdataRender data to search
didDomain ID to match
uidUnique ID to match
Return values
ptrMatching Render data

Definition at line 47 of file helpers.c.

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}
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
+ Here is the caller graph for this function:

◆ find_get_string()

const struct ExpandoRenderData * find_get_string ( const struct ExpandoRenderData rdata,
int  did,
int  uid 
)

Find a get_string() callback function.

Parameters
rdataRender data to search
didDomain ID to match
uidUnique ID to match
Return values
ptrMatching Render data

Definition at line 71 of file helpers.c.

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}
void(* get_string)(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, int max_cols, struct Buffer *buf)
Definition: render.h:65
+ Here is the caller graph for this function:

◆ buf_lower_special()

void buf_lower_special ( struct Buffer buf)

Convert to lowercase, excluding special characters.

Parameters
bufString to lowercase

The string is transformed in place.

Definition at line 176 of file helpers.c.

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}
@ MUTT_TREE_MAX
Definition: mutt_thread.h:71
@ MUTT_SPECIAL_INDEX
Colour indicator.
Definition: mutt_thread.h:73
char * data
Pointer to data.
Definition: buffer.h:37
+ Here is the caller graph for this function: