Here's the whole wrap_string function so you can see exactly what's going on.
// wrap a string "str" at the desired column "col". Defaults to 75
string wrap_string( string str, unsigned int col = 75 )
{
string desc(str);
// if the size of the string is less then col we don't need to do anything
if( desc.size() < col )
return desc;
// if col is less then 50 there's really no point to doing this anyways
if( col < 50 )
return desc;
// strip all excess spaces, ' ', from the string
for( unsigned int i = 0; i < desc.size(); i++ )
if( desc[i] == ' ' && desc[i + 1] == ' ' )
desc = desc.erase(i, 1);
unsigned int loc(col);
bool done = false;
do
{
// well that was easy!
if( desc[loc] == ' ' )
{
desc = desc.replace(loc, 1, "\r"
;
desc = desc.insert(loc + 1, "\n"
;
}
else
{
int a(0), b(0);
// how many characters from current location back is next space
for( int i = loc; desc[i] != ' '; i--, a++ )
;
// how many forwards?
for( int i = loc; desc[i] != ' '; i++, b++ )
;
// wrap at space, ' ', closest to desired column
if( a < b )
{
desc = desc.replace(loc - a, 1, "\r"
;
desc = desc.insert(loc - a, "\n"
;
}
else
{
desc = desc.replace(loc + b, 1, "\r"
;
desc = desc.insert(loc + b, "\n"
;
}
}
loc += col;
if( loc >= desc.size() )
done = true;
} while (!done);
return desc;
}
wrap_string is called in process_room_desc like so: desc = wrap_string(desc);
This is what I see in-game in the room that I'm using to test the whole tag system as well as the actual room desc.
Output:
This is the office of the Immortal Andril. kwe kwe kwe kwe kwe kwe kwe kwe
kwe kwe kwe kwe kwe
Actual description:
1> This is the office of the Immortal Andril.
2> #nelona[test]
3> #elona[test]
4> #relona[relona]
5> kwe
6> kwe
7> kwe
8> kwe
9> kwe
10> kwe
11> kwe
12> kwe
13> kwe
14> kwe
15> kwe
16> kwe
17> kwe
As you can see, lines 2, 3 and 4 have spaces in the beginning because zMUD treats the # sign as special, and I can't get it to stop, so I want to make sure those excess spaces are removed. Which they aren't, for some reason.
Oddly enough, the replace and insert calls work fine. Just not that erase one.