-
Notifications
You must be signed in to change notification settings - Fork 3
/
README.txt
326 lines (217 loc) · 8.93 KB
/
README.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
_____________
BWRAP
Michael Lee
_____________
Table of Contents
_________________
About
Benchmark
Features
Examples(`use_std' feature)
.. Multiple languages
..... English, Ukrainian, Greek, etc.
..... Chinese, Japanese, Thai, etc.
.. Append/prepend
..... Indentation
..... Trailing notation
License
About
=====
Bwrap is a fast, lightweight, embedded environment-friendly library
for wrapping text. While Bwrap offers great flexibility in wrapping
text, neither resource consumption nor performance compromises:
1. No heap allocation happens by default.
2. The time/space complexity is /O(n)/ by default, or /O(n(p+a))/ if
there is appending/prepending. (/n/, /p/, /a/ is the number of
input bytes, prepended bytes, and appended bytes respectively)
For the sake of readability, we (*b*)etter *wrap* our text.
Benchmark
=========
Below are the performance comparisons among several text-wrapping
libraries in different dimensions:
*Time:*
<img src="result-rtime.png" width="500"/>
*Memory:*
<img src="result-mempeak.png" width="500"/>
Note:
1. The benchmark is reproduciable, details about benchmark samples or
methods are elaborated in [bench-wrap-libs].
2. The data above is obtained on an i5-3337u/8G machine and is for
reference only. It is possible to have a slightly different result
on a different machine or with different idle system resource.
[bench-wrap-libs] <https://github.com/micl2e2/bench-wrap-libs>
Features
========
`use_std': Use Rust standard library(libstd) for automatic memory
management.
Examples(`use_std' feature)
===========================
Multiple languages
~~~~~~~~~~~~~~~~~~
Bwrap suuport multiple languages, it categorizes languages into two
categories: *space-sensitive* and *space-insensitive*. The former is
for the languages that depend on ASCII SPACE to delimit words, such as
English, Ukrainian, Greek and so on. The latter is for the languages
that are space-insensitive, such as Chinese, Japanese, Thai and so on.
English, Ukrainian, Greek, etc.
-------------------------------
* English
Original:
,----
| one two three four five six seven eight nine ten one two three four five six seven eight nine ten one two three four five six seven eight nine ten
`----
*Wrapped*:
,----
| one two three four five six seven eight nine ten
| one two three four five six seven eight nine ten
| one two three four five six seven eight nine ten
`----
Source code:
,----
| let line = "one two three four five six seven eight nine ten one two three four five six seven eight nine ten one two three four five six seven eight nine ten";
| println!("ORIGINAL:\n\n{}\n", line);
| println!("WRAPPED:\n\n{}", bwrap::wrap!(line, 50));
`----
* Ukrainian
Original:
,----
| один два три чотири п'ять шість сім вісім дев'ять десять один два три чотири п'ять шість сім вісім дев'ять десять один два три чотири п'ять шість сім вісім дев'ять десять
`----
*Wrapped*:
,----
| один два три чотири п'ять шість сім вісім дев'ять десять
| один два три чотири п'ять шість сім вісім дев'ять десять
| один два три чотири п'ять шість сім вісім дев'ять десять
`----
Source code:
,----
| let line = "один два три чотири п'ять шість сім вісім дев'ять десять один два три чотири п'ять шість сім вісім дев'ять десять один два три чотири п'ять шість сім вісім дев'ять десять";
| println!("ORIGINAL:\n\n{}\n", line);
| println!("WRAPPED:\n\n{}", bwrap::wrap!(line, 60));
`----
* Greek
Original:
,----
| ένα δύο τρία τέσσερα πέντε έξι επτά οκτώ εννέα δέκα ένα δύο τρία τέσσερα πέντε έξι επτά οκτώ εννέα δέκα ένα δύο τρία τέσσερα πέντε έξι επτά οκτώ εννέα δέκα
`----
*Wrapped*:
,----
| ένα δύο τρία τέσσερα πέντε έξι επτά οκτώ εννέα δέκα
| ένα δύο τρία τέσσερα πέντε έξι επτά οκτώ εννέα δέκα
| ένα δύο τρία τέσσερα πέντε έξι επτά οκτώ εννέα δέκα
`----
Source code:
,----
| let line = "ένα δύο τρία τέσσερα πέντε έξι επτά οκτώ εννέα δέκα ένα δύο τρία τέσσερα πέντε έξι επτά οκτώ εννέα δέκα ένα δύο τρία τέσσερα πέντε έξι επτά οκτώ εννέα δέκα";
| println!("ORIGINAL:\n\n{}\n", line);
| println!("WRAPPED:\n\n{}", bwrap::wrap!(line, 51));
`----
Chinese, Japanese, Thai, etc.
-----------------------------
* Chinese
Original:
,----
| 一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十
`----
*Wrapped*:
,----
| 一二三四五六七八九十
| 一二三四五六七八九十
| 一二三四五六七八九十
`----
Source code:
,----
| let line = "一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十";
| println!("ORIGINAL:\n\n{}\n", line);
| println!("WRAPPED:\n\n{}", bwrap::wrap_maybrk!(line, 20));
`----
* Japanese
Original:
,----
| ありがとうございますありがとうございますありがとうございます
`----
*Wrapped*:
,----
| ありがとうございます
| ありがとうございます
| ありがとうございます
`----
Source code:
,----
| let line = "ありがとうございますありがとうございますありがとうございます";
| println!("ORIGINAL:\n\n{}\n", line);
| println!("WRAPPED:\n\n{}", bwrap::wrap_maybrk!(line, 20));
`----
* Thai
Original:
,----
| หนึ่งสองสามสี่ห้าหกเจ็ดแปดเก้าสิบหนึ่งสองสามสี่ห้าหกเจ็ดแปดเก้าสิบหนึ่งสองสามสี่ห้าหกเจ็ดแปดเก้าสิบ
`----
*Wrapped*:
,----
| หนึ่งสองสามสี่ห้าหกเจ็ดแปดเก้าสิบ
| หนึ่งสองสามสี่ห้าหกเจ็ดแปดเก้าสิบ
| หนึ่งสองสามสี่ห้าหกเจ็ดแปดเก้าสิบ
`----
Source code:
,----
| let line = "หนึ่งสองสามสี่ห้าหกเจ็ดแปดเก้าสิบหนึ่งสองสามสี่ห้าหกเจ็ดแปดเก้าสิบหนึ่งสองสามสี่ห้าหกเจ็ดแปดเก้าสิบ";
| println!("ORIGINAL:\n\n{}\n", line);
| println!("WRAPPED:\n\n{}", bwrap::wrap_maybrk!(line, 25));
`----
Append/prepend
~~~~~~~~~~~~~~
Bwrap can append or prepend whatever string to newly added newline
character. With this feature, one can effectively achieve indentation,
line trailing notation or similar.
Indentation
-----------
Original:
,----
| Here is our schedule:
| - Do A, and do B, and do C, and do D, and do E, and do F
| - Do G, and do H, and do I, and do J, and do K, and do L
`----
*Wrapped*:
,----
| Here is our schedule:
| - Do A, and do B, and do C, and do
| D, and do E, and do F
| - Do G, and do H, and do I, and do
| J, and do K, and do L
`----
Source code:
,----
| let line = "Here is our schedule:\n- Do A, and do B, and do C, and do D, and do E, and do F\n- Do G, and do H, and do I, and do J, and do K, and do L";
| println!("ORIGINAL:\n\n{}\n", line);
| println!("WRAPPED:\n\n{}", bwrap::wrap_nobrk!(line, 35, " "));
`----
Trailing notation
-----------------
Original:
,----
| VGhpcyBpcyBhIHNlY3JldCBtZXNzYWdlLCBwbGVhc2UgZGVsZXRlIGFmdGVyIHJlYWQK
`----
*Wrapped*:
,----
| VGhpcyBpcy |
| BhIHNlY3Jl |
| dCBtZXNzYW |
| dlLCBwbGVh |
| c2UgZGVsZX |
| RlIGFmdGVy |
| IHJlYWQK
`----
Source code:
,----
| let line = "VGhpcyBpcyBhIHNlY3JldCBtZXNzYWdlLCBwbGVhc2UgZGVsZXRlIGFmdGVyIHJlYWQK";
| println!("ORIGINAL:\n\n{}\n", line);
| println!("WRAPPED:\n\n{}", bwrap::wrap_maybrk!(line, 10, " |"));
`----
License
=======
Bwrap can be licensed under either [MIT License] or [GNU General
Public License Version 3.0]. The choice is up to the recipient.
[MIT License] <https://github.com/micl2e2/bwrap/blob/master/LICENSE-MIT>
[GNU General Public License Version 3.0]
<https://github.com/micl2e2/bwrap/blob/master/LICENSE-GPL>