NeoMutt  2024-04-25-92-gf10c0f
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 const int num_bytes = node->end - node->start;
48 return format_string(buf, 0, max_cols, JUSTIFY_LEFT, ' ', node->start, num_bytes, 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->start = start;
63 node->end = end;
65
66 return node;
67}
68
76static const char *skip_until_ch_or_end(const char *start, char terminator, const char *end)
77{
78 while (*start)
79 {
80 if (*start == terminator)
81 {
82 break;
83 }
84
85 if (end && (start > (end - 1)))
86 {
87 break;
88 }
89
90 start++;
91 }
92
93 return start;
94}
95
103struct ExpandoNode *node_text_parse(const char *str, const char *end, const char **parsed_until)
104{
105 const char *text_end = skip_until_ch_or_end(str, '%', end);
106 *parsed_until = text_end;
107 return node_text_new(str, text_end);
108}
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.
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:103
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:76
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: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