NeoMutt  2024-12-12-14-g7b49f7
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
node_text.h File Reference

Expando Node for Text. More...

#include <stdint.h>
+ Include dependency graph for node_text.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define NTE_NO_FLAGS   0
 No flags are set.
 
#define NTE_AMPERSAND   (1 << 0)
 '&' Ampersand
 
#define NTE_GREATER   (1 << 1)
 '>' Greater than
 
#define NTE_QUESTION   (1 << 2)
 '?' Question mark
 

Typedefs

typedef uint8_t NodeTextTermFlags
 Special characters that end a text string.
 

Functions

struct ExpandoNodenode_text_new (const char *text)
 Create a new Text ExpandoNode.
 
struct ExpandoNodenode_text_parse (const char *str, NodeTextTermFlags term_chars, const char **parsed_until)
 Extract a block of text.
 

Detailed Description

Expando Node for Text.

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 node_text.h.

Macro Definition Documentation

◆ NTE_NO_FLAGS

#define NTE_NO_FLAGS   0

No flags are set.

Definition at line 33 of file node_text.h.

◆ NTE_AMPERSAND

#define NTE_AMPERSAND   (1 << 0)

'&' Ampersand

Definition at line 34 of file node_text.h.

◆ NTE_GREATER

#define NTE_GREATER   (1 << 1)

'>' Greater than

Definition at line 35 of file node_text.h.

◆ NTE_QUESTION

#define NTE_QUESTION   (1 << 2)

'?' Question mark

Definition at line 36 of file node_text.h.

Typedef Documentation

◆ NodeTextTermFlags

typedef uint8_t NodeTextTermFlags

Special characters that end a text string.

Flags, e.g. NTE_NO_FLAGS

Definition at line 32 of file node_text.h.

Function Documentation

◆ node_text_new()

struct ExpandoNode * node_text_new ( const char *  text)

Create a new Text ExpandoNode.

Parameters
textText to store
Return values
ptrNew Text ExpandoNode
Note
The text will be copied

Definition at line 59 of file node_text.c.

60{
61 struct ExpandoNode *node = node_new();
62
63 node->type = ENT_TEXT;
64 node->text = mutt_str_dup(text);
66
67 return node;
68}
static int node_text_render(const struct ExpandoNode *node, const struct ExpandoRenderCallback *erc, struct Buffer *buf, int max_cols, void *data, MuttFormatFlags flags)
Render a Text Node - Implements ExpandoNode::render() -.
Definition: node_text.c:42
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:253
struct ExpandoNode * node_new(void)
Create a new empty ExpandoNode.
Definition: node.c:39
@ ENT_TEXT
Plain text.
Definition: node.h:38
Basic Expando Node.
Definition: node.h:67
int(* render)(const struct ExpandoNode *node, const struct ExpandoRenderCallback *erc, struct Buffer *buf, int max_cols, void *data, MuttFormatFlags flags)
Definition: node.h:92
const char * text
Node-specific text.
Definition: node.h:73
enum ExpandoNodeType type
Type of Node, e.g. ENT_EXPANDO.
Definition: node.h:68
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ node_text_parse()

struct ExpandoNode * node_text_parse ( const char *  str,
NodeTextTermFlags  term_chars,
const char **  parsed_until 
)

Extract a block of text.

Parameters
[in]strString to parse
[in]term_charsTerminator characters, e.g. NTE_GREATER
[out]parsed_untilFirst character after parsed text
Return values
ptrNew Text ExpandoNode

Parse as much text as possible until the end of the line, or a terminator character is matched.

May return NULL if a terminator character is found immediately.

Note
\ before a character makes it literal
%% is interpreted as a literal % character
'' is always special

Definition at line 86 of file node_text.c.

88{
89 if (!str || (str[0] == '\0') || !parsed_until)
90 return NULL;
91
92 struct Buffer *text = buf_pool_get();
93
94 while (str[0] != '\0')
95 {
96 if (str[0] == '\\') // Literal character
97 {
98 if (str[1] == '\0')
99 {
100 buf_addch(text, '\\');
101 str++;
102 break;
103 }
104
105 buf_addch(text, str[1]);
106 str += 2;
107 continue;
108 }
109
110 if ((str[0] == '%') && (str[1] == '%')) // Literal %
111 {
112 buf_addch(text, '%');
113 str += 2;
114 continue;
115 }
116
117 if (str[0] == '%') // '%' is always special
118 break;
119
120 if ((str[0] == '&') && (term_chars & NTE_AMPERSAND))
121 break;
122
123 if ((str[0] == '>') && (term_chars & NTE_GREATER))
124 break;
125
126 if ((str[0] == '?') && (term_chars & NTE_QUESTION))
127 break;
128
129 buf_addch(text, str[0]); // Plain text
130 str++;
131 }
132
133 *parsed_until = str; // First unused character
134
135 struct ExpandoNode *node = NULL;
136 if (!buf_is_empty(text))
138
140
141 return node;
142}
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:291
size_t buf_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
Definition: buffer.c:241
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:96
struct ExpandoNode * node_text_new(const char *text)
Create a new Text ExpandoNode.
Definition: node_text.c:59
#define NTE_QUESTION
'?' Question mark
Definition: node_text.h:36
#define NTE_GREATER
'>' Greater than
Definition: node_text.h:35
#define NTE_AMPERSAND
'&' Ampersand
Definition: node_text.h:34
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:82
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:96
String manipulation buffer.
Definition: buffer.h:36
+ Here is the call graph for this function:
+ Here is the caller graph for this function: