From 1fe13ae00d76681b04bd3c38227452f87c8b2a8c Mon Sep 17 00:00:00 2001 From: haranp Date: Tue, 24 Apr 2007 07:58:55 +0000 Subject: Moving from snprintf() to std::ostringstream, slowly but surely. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@1356 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/abl-show.cc | 75 +++++++++++++++++++++----------------------- 1 file changed, 36 insertions(+), 39 deletions(-) (limited to 'crawl-ref/source/abl-show.cc') diff --git a/crawl-ref/source/abl-show.cc b/crawl-ref/source/abl-show.cc index 17485c495b..c0650fd859 100644 --- a/crawl-ref/source/abl-show.cc +++ b/crawl-ref/source/abl-show.cc @@ -24,6 +24,7 @@ #include "AppHdr.h" #include "abl-show.h" +#include #include #include #include @@ -327,91 +328,87 @@ std::string print_abilities() const std::string make_cost_description( const struct ability_def &abil ) /***********************************************************************/ { - char tmp_buff[80]; // avoiding string steams for portability - std::string ret = ""; - + std::ostringstream ret; if (abil.mp_cost) { - snprintf( tmp_buff, sizeof(tmp_buff), "%d%s MP", - abil.mp_cost, - (abil.flags & ABFLAG_PERMANENT_MP) ? " Permanent" : "" ); - - ret += tmp_buff; + ret << abil.mp_cost; + if (abil.flags & ABFLAG_PERMANENT_MP) + ret << " Permanent"; + ret << " MP"; } if (abil.hp_cost) { - if (ret.length()) - ret += ", "; + if (ret.str().length()) + ret << ", "; - snprintf( tmp_buff, sizeof(tmp_buff), "%d%s HP", - abil.hp_cost, - (abil.flags & ABFLAG_PERMANENT_HP) ? " Permanent" : "" ); - - ret += tmp_buff; + ret << abil.hp_cost; + if (abil.flags & ABFLAG_PERMANENT_HP) + ret << " Permanent"; + ret << " HP"; } if (abil.food_cost) { - if (ret.length()) - ret += ", "; + if (ret.str().length()) + ret << ", "; - ret += "Food"; // randomized and amount hidden from player + ret << "Food"; // randomized and amount hidden from player } if (abil.piety_cost) { - if (ret.length()) - ret += ", "; + if (ret.str().length()) + ret << ", "; - ret += "Piety"; // randomized and amount hidden from player + ret << "Piety"; // randomized and amount hidden from player } if (abil.flags & ABFLAG_BREATH) { - if (ret.length()) - ret += ", "; + if (ret.str().length()) + ret << ", "; - ret += "Breath"; + ret << "Breath"; } if (abil.flags & ABFLAG_DELAY) { - if (ret.length()) - ret += ", "; + if (ret.str().length()) + ret << ", "; - ret += "Delay"; + ret << "Delay"; } if (abil.flags & ABFLAG_PAIN) { - if (ret.length()) - ret += ", "; + if (ret.str().length()) + ret << ", "; - ret += "Pain"; + ret << "Pain"; } if (abil.flags & ABFLAG_EXHAUSTION) { - if (ret.length()) - ret += ", "; + if (ret.str().length()) + ret << ", "; - ret += "Exhaustion"; + ret << "Exhaustion"; } if (abil.flags & ABFLAG_INSTANT) { - if (ret.length()) - ret += ", "; + if (ret.str().length()) + ret << ", "; - ret += "Instant"; // not really a cost, more of a bonus -bwr + ret << "Instant"; // not really a cost, more of a bonus -bwr } // If we haven't output anything so far, then the effect has no cost - if (!ret.length()) - ret += "None"; + if (!ret.str().length()) + ret << "None"; - return (ret); + return (ret.str()); } std::vector get_ability_names() -- cgit v1.2.3-54-g00ecf