-
Notifications
You must be signed in to change notification settings - Fork 0
/
WordWrap.bi
50 lines (46 loc) · 1.32 KB
/
WordWrap.bi
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
#IFNDEF __WORDWRAP_BI__
#DEFINE __WORDWRAP_BI__
#include "CSYMath.bi"
function quote(InParam as string) as string
return chr(34)+InParam+chr(34)
end function
function word_wrap(Text as string) as string
dim as ushort RefChar, RaisedChar, TotalRaised, Cap
dim as string OutText = Text
Cap = loWord(width)
for WID as ushort = 1 to len(Text)
if mid(Text,WID,1) = chr(32) then
RefChar = WID
end if
if mid(Text,WID,2) = "\n" then
RefChar = WID
if RefChar > 0 then
RaisedChar = Cap - remainder(RefChar+TotalRaised,Cap) - 1
else
RaisedChar = 0
end if
OutText = left(OutText,RefChar+TotalRaised-1)+space(RaisedChar)+right(OutText,len(OutText)-TotalRaised-RefChar+1)
TotalRaised += RaisedChar
RefChar = 0
elseif remainder(WID+TotalRaised,Cap) = 0 then
if RefChar > 0 then
RaisedChar = Cap - remainder(RefChar+TotalRaised,Cap)
else
RaisedChar = 0
end if
if RaisedChar = Cap then
RaisedChar = 0
end if
OutText = left(OutText,RefChar+TotalRaised-1)+space(RaisedChar)+right(OutText,len(OutText)-TotalRaised-RefChar+1)
TotalRaised += RaisedChar
RefChar = 0
end if
next WID
for WID as ushort = 1 to len(OutText)
if mid(OutText,WID,2) = "\n" then
OutText = left(OutText,WID-1) + " " + right(OutText,len(OutText)-WID-1)
end if
next WID
return OutText
end function
#ENDIF