NeoMutt  2024-10-02-37-gfa9146
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
node_text.c
Go to the documentation of this file.
1
30#include "config.h"
31#include <stdbool.h>
32#include "mutt/lib.h"
33#include "node_text.h"
34#include "format.h"
35#include "node.h"
36#include "render.h"
37
41static int node_text_render(const struct ExpandoNode *node,
42 const struct ExpandoRenderData *rdata, struct Buffer *buf,
43 int max_cols, void *data, MuttFormatFlags flags)
44{
45 ASSERT(node->type == ENT_TEXT);
46
47 return format_string(buf, 0, max_cols, JUSTIFY_LEFT, ' ', node->text,
48 mutt_str_len(node->text), false);
49}
50
57struct ExpandoNode *node_text_new(const char *start, const char *end)
58{
59 struct ExpandoNode *node = node_new();
60
61 node->type = ENT_TEXT;
62 node->text = mutt_strn_dup(start, end - start);
64
65 return node;
66}
67
75static const char *skip_until_ch_or_end(const char *start, char terminator, const char *end)
76{
77 while (*start)
78 {
79 if (*start == terminator)
80 {
81 break;
82 }
83
84 if (end && (start > (end - 1)))
85 {
86 break;
87 }
88
89 start++;
90 }
91
92 return start;
93}
94
102struct ExpandoNode *node_text_parse(const char *str, const char *end, const char **parsed_until)
103{
104 const char *text_end = skip_until_ch_or_end(str, '%', end);
105 *parsed_until = text_end;
106 return node_text_new(str, text_end);
107}
int format_string(struct Buffer *buf, int min_cols, int max_cols, enum FormatJustify justify, char pad_char, const char *str, size_t n, bool arboreal)
Format a string, like snprintf()
Definition: format.c:108
Simple string formatting.
@ JUSTIFY_LEFT
Left justify the text.
Definition: format.h:34
static int node_text_render(const struct ExpandoNode *node, const struct ExpandoRenderData *rdata, struct Buffer *buf, int max_cols, void *data, MuttFormatFlags flags)
Render a Text Node - Implements ExpandoNode::render() -.
Definition: node_text.c:41
Convenience wrapper for the library headers.
char * mutt_strn_dup(const char *begin, size_t len)
Duplicate a sub-string.
Definition: string.c:380
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:496
struct ExpandoNode * node_new(void)
Create a new empty ExpandoNode.
Definition: node.c:39
Basic Expando Node.
@ ENT_TEXT
Plain text.
Definition: node.h:38
struct ExpandoNode * node_text_new(const char *start, const char *end)
Create a new Text ExpandoNode.
Definition: node_text.c:57
struct ExpandoNode * node_text_parse(const char *str, const char *end, const char **parsed_until)
Extract a block of text.
Definition: node_text.c:102
static const char * skip_until_ch_or_end(const char *start, char terminator, const char *end)
Search for a terminator character.
Definition: node_text.c:75
Expando Node for Text.
Render Expandos using Data.
uint8_t MuttFormatFlags
Flags for expando_render(), e.g. MUTT_FORMAT_FORCESUBJ.
Definition: render.h:32
#define ASSERT(COND)
Definition: signal2.h:58
String manipulation buffer.
Definition: buffer.h:36
Basic Expando Node.
Definition: node.h:67
int(* render)(const struct ExpandoNode *node, const struct ExpandoRenderData *rdata, struct Buffer *buf, int max_cols, void *data, MuttFormatFlags flags)
Definition: node.h:91
const char * text
Node-specific text.
Definition: node.h:73
enum ExpandoNodeType type
Type of Node, e.g. ENT_EXPANDO.
Definition: node.h:68