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 )
// if the size of the string is less then col we don't need to do anything
if( desc.size() < col )
// if col is less then 50 there's really no point to doing this anyways
if( col < 50 )
// 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;
// well that was easy!
if( desc[loc] == ' ' )
desc = desc.replace(loc, 1, "\r"
desc = desc.insert(loc + 1, "\n"
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"
desc = desc.replace(loc + b, 1, "\r"
desc = desc.insert(loc + b, "\n"
loc += col;
if( loc >= desc.size() )
done = true;
} while (!done);
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.
This is the office of the Immortal Andril. kwe kwe kwe kwe kwe kwe kwe kwe
kwe kwe kwe kwe kwe
1> This is the office of the Immortal Andril.
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.