NeoMutt  2024-04-25-1-g3de005
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 <assert.h>
32#include <stdbool.h>
33#include "node_text.h"
34#include "format.h"
35#include "node.h"
36#include "render.h"
37
38struct Buffer;
39
43static int node_text_render(const struct ExpandoNode *node,
44 const struct ExpandoRenderData *rdata, struct Buffer *buf,
45 int max_cols, void *data, MuttFormatFlags flags)
46{
47 assert(node->type == ENT_TEXT);
48
49 const int num_bytes = node->end - node->start;
50 return format_string(buf, 0, max_cols, JUSTIFY_LEFT, ' ', node->start, num_bytes, false);
51}
52
59struct ExpandoNode *node_text_new(const char *start, const char *end)
60{
61 struct ExpandoNode *node = node_new();
62
63 node->type = ENT_TEXT;
64 node->start = start;
65 node->end = end;
67
68 return node;
69}
70
78static const char *skip_until_ch_or_end(const char *start, char terminator, const char *end)
79{
80 while (*start)
81 {
82 if (*start == terminator)
83 {
84 break;
85 }
86
87 if (end && (start > (end - 1)))
88 {
89 break;
90 }
91
92 start++;
93 }
94
95 return start;
96}
97
105struct ExpandoNode *node_text_parse(const char *str, const char *end, const char **parsed_until)
106{
107 const char *text_end = skip_until_ch_or_end(str, '%', end);
108 *parsed_until = text_end;
109 return node_text_new(str, text_end);
110}
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:43
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:59
struct ExpandoNode * node_text_parse(const char *str, const char *end, const char **parsed_until)
Extract a block of text.
Definition: node_text.c:105
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:78
Expando Node for Text.
Render Expandos using Data.
uint8_t MuttFormatFlags
Flags for expando_render(), e.g. MUTT_FORMAT_FORCESUBJ.
Definition: render.h:32
String manipulation buffer.
Definition: buffer.h:36
char * data
Pointer to data.
Definition: buffer.h:37
Basic Expando Node.
Definition: node.h:69
int(* render)(const struct ExpandoNode *node, const struct ExpandoRenderData *rdata, struct Buffer *buf, int max_cols, void *data, MuttFormatFlags flags)
Definition: node.h:96
const char * end
End of string data.
Definition: node.h:80
enum ExpandoNodeType type
Type of Node, e.g. ENT_EXPANDO.
Definition: node.h:70
const char * start
Start of string data.
Definition: node.h:79