Qore TextWrap Module Reference 1.0
Loading...
Searching...
No Matches
TextWrap.qm.dox.h
1// -*- mode: c++; indent-tabs-mode: nil -*-
3
4/* TextWrap.qm Copyright 2023 Qore Technologies, s.r.o.
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23*/
24
25// minimum required Qore version
26
27
28
29
62namespace Init {
63 init();
64
65};
66
68namespace TextWrap {
69
70// Hardcode the recognized whitespace characters to the US-ASCII
71// whitespace characters. The main reason for doing this is that
72// some Unicode spaces (like \u00a0) are non-breaking whitespaces.
73const c_whitespace = "\t\n\013\014\r ";
74
75// -- Private helpers ---------------------------------------------------
76
77any sum (list la, *any start);
78
79
80string translate (string text, hash table);
81
82
83string xsprintf (string fmt, hash args);
84
85
86// -- Public helpers ----------------------------------------------------
87
89
112 string expandtabs (string text, int tabsize = 8);
113
114
115// -- Public functionality ----------------------------------------------
116
165
166public:
167 int width = 70;
168 string initial_indent = "";
169 string subsequent_indent = "";
170 bool expand_tabs = True;
171 bool replace_whitespace = True;
172 bool fix_sentence_endings = False;
173 bool break_long_words = True;
174 bool drop_whitespace = True;
175 bool break_on_hyphens = True;
176 int tabsize = 8;
177 int max_lines;
178 string placeholder = ' [...]';
179
180protected:
181 hash whitespace_trans;
182 string wordsep_re;
183 string wordsep_simple_re;
184 string sentence_end_re;
185
186public:
187
188 constructor (*hash opts);
189
190
191 // -- Private methods -----------------------------------------------
192 // (possibly useful for subclasses to override)
193
201protected:
202 string _munge_whitespace (string text);
203public:
204
205
229 list _split (string text);
230
231
241protected:
242 _fix_sentence_endings (reference chunks);
243public:
244
245
254protected:
255 _handle_long_word (reference reversed_chunks, reference cur_line, int cur_len, int width);
256public:
257
258
272protected:
273 list _wrap_chunks (list chunks);
274public:
275
276
277protected:
278 list _split_chunks (string text);
279public:
280
281
282 // -- Public interface ----------------------------------------------
283
285
294 list wrap (string text);
295
297
304 string fill (string text);
305};
306
307// -- Convenience interface ---------------------------------------------
308
310
318 list wrap (string text, int width=70, *hash opts);
319
320
322
329 string fill (string text, int width=70, *hash opts);
330
331
333
345 string shorten (string text, int width, *hash opts);
346
347
348// -- Loosely related functionality -------------------------------------
349
350const c_whitespace_only_re = '^[ \t]+$';
351const c_leading_whitespace_re = '(^[ \t]*)(?:[^ \t\n])';
352
354
363 string dedent (string text);
364
365
367
373 string indent (string text, string prefix, *code predicate);
374
375
376}; // namespace TextWrap
377
378// vim:et:sw=4:ts=4:sts=4:
Definition: TextWrap.qm.dox.h:164
list wrap(string text)
Wrap a single paragraph of text, returning a list of wrapped lines.
_handle_long_word(reference reversed_chunks, reference cur_line, int cur_len, int width)
list _wrap_chunks(list chunks)
string fill(string text)
Fill a single paragraph of text, returning a new string.
string _munge_whitespace(string text)
_fix_sentence_endings(reference chunks)
list _split(string text)
Main namespace for all public symbols in the TextWrap module.
Definition: TextWrap.qm.dox.h:68
string dedent(string text)
Remove any common leading whitespace from every line in 'text'.
list wrap(string text, int width=70, *hash opts)
Wrap a single paragraph of text, returning a list of wrapped lines.
string indent(string text, string prefix, *code predicate)
Adds 'prefix' to the beginning of selected lines in 'text'.
string shorten(string text, int width, *hash opts)
Collapse and truncate the given text to fit in the given width.
string fill(string text, int width=70, *hash opts)
Fill a single paragraph of text, returning a new string.
string expandtabs(string text, int tabsize=8)
Return a copy of the string where all tab characters are expanded using spaces.