summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/menu.cc
diff options
context:
space:
mode:
authorj-p-e-g <j-p-e-g@c06c8d41-db1a-0410-9941-cceddc491573>2008-02-27 23:37:25 +0000
committerj-p-e-g <j-p-e-g@c06c8d41-db1a-0410-9941-cceddc491573>2008-02-27 23:37:25 +0000
commit1ef02b64bcc1eb7cafcd00b37788f82ea9b782ef (patch)
tree991765f4e74a497625aa73115eeae71dc2940758 /crawl-ref/source/menu.cc
parentf2f6755ac03381e211e1bc818ecc4265f852f908 (diff)
downloadcrawl-ref-1ef02b64bcc1eb7cafcd00b37788f82ea9b782ef.tar.gz
crawl-ref-1ef02b64bcc1eb7cafcd00b37788f82ea9b782ef.zip
Apply Paul's patch 1895083: linebreak_string2 cleanup
I ran a few tests and found no problems whatsoever. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@3473 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/menu.cc')
-rw-r--r--crawl-ref/source/menu.cc35
1 files changed, 21 insertions, 14 deletions
diff --git a/crawl-ref/source/menu.cc b/crawl-ref/source/menu.cc
index e7a527a972..87462a3651 100644
--- a/crawl-ref/source/menu.cc
+++ b/crawl-ref/source/menu.cc
@@ -1364,7 +1364,7 @@ int linebreak_string( std::string& s, int wrapcol, int maxcol )
int linebreak_string2( std::string& s, int maxcol )
{
size_t loc = 0;
- int xpos = 0, spacepos = 0;
+ int xpos = 0, spaceloc = 0;
int breakcount = 0;
while ( loc < s.size() )
{
@@ -1385,32 +1385,39 @@ int linebreak_string2( std::string& s, int maxcol )
}
else
{
- // user-forced newline
+ // user-forced newline, or one we just stuffed in
if ( s[loc] == '\n' )
+ {
xpos = 0;
- // hard linebreak
- else if ( xpos >= maxcol )
+ spaceloc = 0;
+ ++loc;
+ continue;
+ }
+
+ // force a wrap?
+ if ( xpos >= maxcol )
{
- if (spacepos >= xpos-maxcol)
+ if (spaceloc)
{
- loc = spacepos;
+ loc = spaceloc;
s.replace(loc, 1, "\n");
}
else
+ {
s.insert(loc, "\n");
- xpos = 0;
+ }
++breakcount;
+ // reset pointers when we come around and see the \n
+ continue;
}
- // soft linebreak
- else if ( s[loc] == ' ' && xpos > 0)
+
+ // save possible linebreak location
+ if ( s[loc] == ' ' && xpos > 0)
{
- spacepos = loc;
- ++xpos;
+ spaceloc = loc;
}
- // bog-standard
- else
- ++xpos;
+ ++xpos;
++loc;
}
}