2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
5 * A very simple word wrapping encoder.
7 #include "wvwordwrap.h"
9 WvWordWrapEncoder::WvWordWrapEncoder(int _maxwidth
) :
12 line
= new char[maxwidth
];
17 WvWordWrapEncoder::~WvWordWrapEncoder()
23 bool WvWordWrapEncoder::_reset()
26 curindex
= wordindex
= 0;
32 bool WvWordWrapEncoder::_encode(WvBuf
&inbuf
, WvBuf
&outbuf
,
35 while (inbuf
.used() != 0)
37 int ch
= inbuf
.getch();
52 if (width
<= maxwidth
)
53 line
[curindex
++] = ch
;
59 width
= (width
+ 8) & ~7;
60 if (width
<= maxwidth
)
61 line
[curindex
++] = ch
;
65 if (width
>= maxwidth
)
69 // discard trailing whitespace
70 curindex
= wordindex
= 0;
73 else if (wordindex
== 0)
75 // insert hard line break
81 // insert soft line break
82 curindex
-= wordindex
;
83 memmove(line
, line
+ wordindex
, curindex
);
95 line
[curindex
++] = ch
;
106 void WvWordWrapEncoder::flushline(WvBuf
&outbuf
)
108 outbuf
.put(line
, curindex
);
109 curindex
= wordindex
= 0;