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 2022 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}
30
63namespace Init {
64 init();
65
66};
67
69namespace TextWrap {
70
71// Hardcode the recognized whitespace characters to the US-ASCII
72// whitespace characters. The main reason for doing this is that
73// some Unicode spaces (like \u00a0) are non-breaking whitespaces.
74const c_whitespace = "\t\n\013\014\r ";
75
76// -- Private helpers ---------------------------------------------------
77
78any sum (list la, *any start);
79
80
81string translate (string text, hash table);
82
83
84string xsprintf (string fmt, hash args);
85
86
87// -- Public helpers ----------------------------------------------------
88
90
113 string expandtabs (string text, int tabsize = 8);
114
115
116// -- Public functionality ----------------------------------------------
117
166
167public:
168 int width = 70;
169 string initial_indent = "";
170 string subsequent_indent = "";
171 bool expand_tabs = True;
172 bool replace_whitespace = True;
173 bool fix_sentence_endings = False;
174 bool break_long_words = True;
175 bool drop_whitespace = True;
176 bool break_on_hyphens = True;
177 int tabsize = 8;
178 int max_lines;
179 string placeholder = ' [...]';
180
181protected:
182 hash whitespace_trans;
183 string wordsep_re;
184 string wordsep_simple_re;
185 string sentence_end_re;
186
187public:
188
189 constructor (*hash opts);
190
191
192 // -- Private methods -----------------------------------------------
193 // (possibly useful for subclasses to override)
194
202protected:
203 string _munge_whitespace (string text);
204public:
205
206
230 list _split (string text);
231
232
242protected:
243 _fix_sentence_endings (reference chunks);
244public:
245
246
255protected:
256 _handle_long_word (reference reversed_chunks, reference cur_line, int cur_len, int width);
257public:
258
259
273protected:
274 list _wrap_chunks (list chunks);
275public:
276
277
278protected:
279 list _split_chunks (string text);
280public:
281
282
283 // -- Public interface ----------------------------------------------
284
286
295 list wrap (string text);
296
298
305 string fill (string text);
306};
307
308// -- Convenience interface ---------------------------------------------
309
311
319 list wrap (string text, int width=70, *hash opts);
320
321
323
330 string fill (string text, int width=70, *hash opts);
331
332
334
346 string shorten (string text, int width, *hash opts);
347
348
349// -- Loosely related functionality -------------------------------------
350
351const c_whitespace_only_re = '^[ \t]+$';
352const c_leading_whitespace_re = '(^[ \t]*)(?:[^ \t\n])';
353
355
364 string dedent (string text);
365
366
368
374 string indent (string text, string prefix, *code predicate);
375
376
377}; // namespace TextWrap
378
379// vim:et:sw=4:ts=4:sts=4:
Definition: TextWrap.qm.dox.h:165
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:69
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.