Oliver
Magician


Group: Members
Posts: 81
Joined: Apr 24, 2010
|
#16 id:47116 Posted Jun 15, 2010, 2:19 am
|
I'm going to bump this thread!
I've looked over it again and I would really appreciate some help from anyone with this problem. A new and improved format_string() function in the repository could be helpful to a lot of people, I think.
The magickery involved in the original function has eluded my thoroughly mediocre code-fixing expertise.
|
|
|
Hades_Kane
Wizard


Group: Moderators
Posts: 817
Joined: May 31, 2006
|
#17 id:47119 Posted Jun 15, 2010, 2:38 pm
|
I would be happy to help if it were my code... You might send bbailey a private message and ask him if you could have it since that's where I got it.
|
......................... -Diablos of End of Time, eotmud.com:4000, Final Fantasy themed -- Seeking Builders! For more info visit: http://www.eotmud.com/
|
|
Oliver
Magician


Group: Members
Posts: 81
Joined: Apr 24, 2010
|
#18 id:47120 Posted Jun 15, 2010, 5:27 pm
|
With a little bit of digging, I actually found a fixed version of the code in a set of code in the repository. It's not labeled as an improvement to the format code. Later today, I'll upload the snippet with credit to its authors.
I'll link it here after I've done that, seeing as how it seems like more people than just I have had problems with the stock OLC function.
|
|
|
Runter
Wizard


Group: Members
Posts: 1,850
Joined: Jun 1, 2006
|
#19 id:47121 Posted Jun 15, 2010, 8:14 pm
|
Some code I wrote to do it recursively. Need to be cleaned up some, but it gets the job done.
http://codepad.org/aqZBsvKd
|
......................... CoralMud project
For once you have tasted flight Ruby you will walk the earth with your eyes turned skywards,
for there you have been and there you will long to return. --
Leonardo Da Vinci Yukihiro Matsumoto
|
|
Runter
Wizard


Group: Members
Posts: 1,850
Joined: Jun 1, 2006
|
#20 id:47123 Posted Jun 15, 2010, 10:20 pm
|
And just for the heck of it here is the same thing in Ruby.
http://codepad.org/EVjZ8yt4
|
......................... CoralMud project
For once you have tasted flight Ruby you will walk the earth with your eyes turned skywards,
for there you have been and there you will long to return. --
Leonardo Da Vinci Yukihiro Matsumoto
|
|
Runter
Wizard


Group: Members
Posts: 1,850
Joined: Jun 1, 2006
|
#21 id:47335 Posted Jun 19, 2010, 9:46 pm
|
More Rubyesque.
http://codepad.org/AF544QCT
Code (Ruby): 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 | # extend String class to define format method.
class String
def format(count=80, preserve=false)
# split the string, then collect the raw_format as an array, and join the entire array into one string.
split("\n",-1).collect! { |each_paragraph| if preserve then "" else " " end + each_paragraph.raw_format!(count, preserve)}.join("\n")
end
# format a string raw. sub out any line feeds.
def raw_format!(count=80, preserve=false)
lstrip! unless preserve # strip leading spaces.
return self if length < count
# Look for a space, break it off there, then recursively call the function again.
(count-1).downto(0) do |backwards_offset|
if self[backwards_offset].chr == ' ' # Split here if it's a space.
part = (self.slice!(0...backwards_offset) || "") + "\n"
return part + self.raw_format!(count)
end
end
return self # if we get this far then there was no space.
end
end
|
Output with test strings:
Code (text): 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 |
Preservation mode:
855 He seyde, "Syn I shal bigynne the game,
What, welcome be the cut, a Goddes name!
Now lat us ryde, and herkneth what I seye."
And with that word we ryden forth oure weye,
And he bigan with right a myrie cheere
860 His tale anon, and seyde as ye may heere.
No preservation:
Suspendisse semper urna. Aenean ullamcorper pede nunc eu lectus eget nisl.
Donec sollicitudin vitae, Curabitur ultrices urna, id erat sit amet, est. Duis
quam tristique senectus et interdum eu, luctus et enim. Mauris convallis
varius. Morbi placerat quis,
felis. augue. Maecenas interdum adipiscing elit. Ut id diam mauris, adipiscing
elit. Nam nec felis tincidunt est sem, accumsan eu, ullamcorper lorem. Donec at
laoreet risus. Phasellus dignissim. Nunc vulputate. Morbi accumsan
consectetuer ut, tempus ultrices, gravida sit amet, consectetuer vulputate
vitae, mauris. Pellentesque molestie sed, viverra auctor, ante imperdiet orci
id ipsum. Proin cursus aliquam.
|
|
......................... CoralMud project
For once you have tasted flight Ruby you will walk the earth with your eyes turned skywards,
for there you have been and there you will long to return. --
Leonardo Da Vinci Yukihiro Matsumoto
Last edited Jun 19, 2010, 9:48 pm by Runter
|
|
|
|
Noplex
Conjurer


Group: Members
Posts: 105
Joined: May 20, 2006
|
#23 id:47423 Posted Jun 21, 2010, 5:43 pm
|
I clicked on this thread because whenever I see .f I immediately wonder who in their right mind is writing Fortran nowadays. It seems I'm the only fool stuck maintaining it :-).
|
|
......................... jb
|
|
Oliver
Magician


Group: Members
Posts: 81
Joined: Apr 24, 2010
|
#24 id:49432 Posted Aug 15, 2010, 10:01 pm
|
As a heads up, I uploaded the format_string() function I found. It preserves intentional newlines when formatting. It seems like there've been more people than just me who had problems.
Here it is: http://www.mudbytes.net/file-2768
|
|
|