summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--crawl-ref/source/command.cc3
-rw-r--r--crawl-ref/source/format.cc93
-rw-r--r--crawl-ref/source/format.h4
-rw-r--r--crawl-ref/source/item_use.cc10
-rw-r--r--crawl-ref/source/itemname.cc2
-rw-r--r--crawl-ref/source/items.cc2
-rw-r--r--crawl-ref/source/output.cc3
-rw-r--r--crawl-ref/source/quiver.cc3
-rw-r--r--crawl-ref/source/spl-cast.cc37
-rw-r--r--crawl-ref/source/stuff.cc2
10 files changed, 106 insertions, 53 deletions
diff --git a/crawl-ref/source/command.cc b/crawl-ref/source/command.cc
index dcdb6e831e..bfe6ace2f1 100644
--- a/crawl-ref/source/command.cc
+++ b/crawl-ref/source/command.cc
@@ -681,8 +681,7 @@ void list_weapons(void)
// Now we print out the current default fire weapon.
wstring = "Firing : ";
- std::string error_reason;
- int slot = you.m_quiver->get_fire_item(&error_reason);
+ int slot = you.m_quiver->get_fire_item();
colour = MSGCOL_BLACK;
if (slot == -1)
diff --git a/crawl-ref/source/format.cc b/crawl-ref/source/format.cc
index e4280e5038..9cd282e058 100644
--- a/crawl-ref/source/format.cc
+++ b/crawl-ref/source/format.cc
@@ -577,3 +577,96 @@ int count_linebreaks(const formatted_string& fs)
}
return count;
}
+
+// Return the actual (string) offset of character #loc to be printed,
+// i.e. ignoring tags. So for instance, if s == "<tag>ab</tag>", then
+// _find_string_location(s, 2) == 6.
+int _find_string_location(const std::string& s, int loc)
+{
+ int real_offset = 0;
+ bool in_tag = false;
+ int last_taglen = 0;
+ int offset = 0;
+ for (std::string::const_iterator ci = s.begin();
+ ci != s.end() && real_offset < loc;
+ ++ci, ++offset)
+ {
+ if (in_tag)
+ {
+ if (*ci == '<' && last_taglen == 1)
+ {
+ ++real_offset;
+ in_tag = false;
+ }
+ else if (*ci == '>')
+ {
+ in_tag = false;
+ }
+ else
+ {
+ ++last_taglen;
+ }
+ }
+ else if (*ci == '<')
+ {
+ in_tag = true;
+ last_taglen = 1;
+ }
+ else
+ {
+ ++real_offset;
+ }
+ }
+ return (offset);
+}
+
+// Return the substring of s from character start to character end,
+// where tags count as length 0.
+std::string tagged_string_substr(const std::string& s, int start, int end)
+{
+ return (s.substr(_find_string_location(s, start),
+ _find_string_location(s, end)));
+}
+
+int tagged_string_printable_length(const std::string& s)
+{
+ int len = 0;
+ bool in_tag = false;
+ int last_taglen = 0;
+ for (std::string::const_iterator ci = s.begin(); ci != s.end(); ++ci)
+ {
+ if (in_tag)
+ {
+ if (*ci == '<' && last_taglen == 1) // "<<" sequence
+ {
+ in_tag = false; // this is an escape for '<'
+ ++len; // len wasn't incremented before
+ }
+ else if (*ci == '>') // tag close, still nothing printed
+ {
+ in_tag = false;
+ }
+ else // tag continues
+ {
+ ++last_taglen;
+ }
+ }
+ else if (*ci == '<') // tag starts
+ {
+ in_tag = true;
+ last_taglen = 1;
+ }
+ else // normal, printable character
+ {
+ ++len;
+ }
+ }
+ return (len);
+}
+
+
+// Count the length of the tags in the string.
+int tagged_string_tag_length(const std::string& s)
+{
+ return s.size() - tagged_string_printable_length(s);
+}
diff --git a/crawl-ref/source/format.h b/crawl-ref/source/format.h
index 3e7bc4374f..9ddd43576d 100644
--- a/crawl-ref/source/format.h
+++ b/crawl-ref/source/format.h
@@ -114,4 +114,8 @@ public:
int count_linebreaks(const formatted_string& fs);
+int tagged_string_tag_length(const std::string& s);
+int tagged_string_printable_length(const std::string& s);
+std::string tagged_string_substr(const std::string& s, int start, int end);
+
#endif
diff --git a/crawl-ref/source/item_use.cc b/crawl-ref/source/item_use.cc
index 3d6c9c6f24..bf47e513ff 100644
--- a/crawl-ref/source/item_use.cc
+++ b/crawl-ref/source/item_use.cc
@@ -1294,10 +1294,6 @@ void fire_target_behaviour::message_ammo_prompt(const std::string* pre_text)
const int next_item = get_next_fire_item(m_slot, +1);
bool no_other_items = (next_item == -1 || next_item == m_slot);
- // How many letters are only needed for formatting, but won't ever
- // be printed.
- int colour_length = 0;
-
mesclr();
if (pre_text)
@@ -1329,7 +1325,6 @@ void fire_target_behaviour::message_ammo_prompt(const std::string* pre_text)
if (m_slot == -1)
{
msg << "<red>" << m_noitem_reason << "</red>";
- colour_length = 5;
}
else
{
@@ -1337,11 +1332,10 @@ void fire_target_behaviour::message_ammo_prompt(const std::string* pre_text)
msg << "<" << colour << ">"
<< you.inv[m_slot].name(DESC_INVENTORY_EQUIP)
<< "</" << colour << ">";
- colour_length = (selected_from_inventory ? 11 : 3);
}
- formatted_message_history(msg.str()
- .substr(0, crawl_view.msgsz.x + colour_length),
+ formatted_message_history(tagged_string_substr(msg.str(),
+ 0, crawl_view.msgsz.x),
MSGCH_PROMPT);
}
diff --git a/crawl-ref/source/itemname.cc b/crawl-ref/source/itemname.cc
index fd6dcb96fb..2ae8e1a8a0 100644
--- a/crawl-ref/source/itemname.cc
+++ b/crawl-ref/source/itemname.cc
@@ -227,7 +227,7 @@ std::string item_def::name(description_level_type descrip,
buff << " (around neck)";
equipped = true;
}
- else if (this->link == you.m_quiver->get_fire_item(NULL))
+ else if (this->link == you.m_quiver->get_fire_item())
{
buff << " (quivered)";
equipped = true; // well, sort of
diff --git a/crawl-ref/source/items.cc b/crawl-ref/source/items.cc
index 3c909be853..9aff646578 100644
--- a/crawl-ref/source/items.cc
+++ b/crawl-ref/source/items.cc
@@ -2440,7 +2440,7 @@ bool item_is_equipped(const item_def &item, bool quiver_too)
if (item.link == you.equip[i])
return (true);
- if (quiver_too && item.link == you.m_quiver->get_fire_item(NULL))
+ if (quiver_too && item.link == you.m_quiver->get_fire_item())
return (true);
return (false);
diff --git a/crawl-ref/source/output.cc b/crawl-ref/source/output.cc
index fd97e6a5ec..dab690ae97 100644
--- a/crawl-ref/source/output.cc
+++ b/crawl-ref/source/output.cc
@@ -495,8 +495,7 @@ static void _print_stats_qv(int y)
textcolor(Options.status_caption_colour);
cprintf("Qv: ");
- std::string error_reason;
- int q = you.m_quiver->get_fire_item(&error_reason);
+ int q = you.m_quiver->get_fire_item();
ASSERT(q >= -1 && q < ENDOFPACK);
if (q != -1)
diff --git a/crawl-ref/source/quiver.cc b/crawl-ref/source/quiver.cc
index 12b8d5a9ad..c1582ab6ff 100644
--- a/crawl-ref/source/quiver.cc
+++ b/crawl-ref/source/quiver.cc
@@ -294,8 +294,7 @@ void player_quiver::on_inv_quantity_changed(int slot, int amt)
else
{
// We might need to update the quiver...
- std::string error_reason;
- int qv_slot = get_fire_item(&error_reason);
+ int qv_slot = get_fire_item();
if (qv_slot == slot)
you.redraw_quiver = true;
}
diff --git a/crawl-ref/source/spl-cast.cc b/crawl-ref/source/spl-cast.cc
index 826d84bd91..5abc08b98b 100644
--- a/crawl-ref/source/spl-cast.cc
+++ b/crawl-ref/source/spl-cast.cc
@@ -168,41 +168,6 @@ static std::string _spell_base_description(spell_type spell)
return desc.str();
}
-static int _string_tag_length(const std::string& s)
-{
- int taglen = 0;
- bool in_tag = false;
- int last_taglen = 0;
- for (std::string::const_iterator ci = s.begin(); ci != s.end(); ++ci)
- {
- if (in_tag)
- {
- if (*ci == '<' && last_taglen == 1)
- {
- in_tag = false;
- --taglen;
- }
- else if (*ci == '>')
- {
- in_tag = false;
- ++taglen;
- }
- else
- {
- ++last_taglen;
- ++taglen;
- }
- }
- else if (*ci == '<')
- {
- in_tag = true;
- last_taglen = 1;
- ++taglen;
- }
- }
- return (taglen);
-}
-
static std::string _spell_extra_description(spell_type spell)
{
std::ostringstream desc;
@@ -216,7 +181,7 @@ static std::string _spell_extra_description(spell_type spell)
const std::string rangestring = spell_range_string(spell);
desc << std::setw(14) << spell_power_string(spell)
- << std::setw(16 + _string_tag_length(rangestring)) << rangestring
+ << std::setw(16 + tagged_string_tag_length(rangestring)) << rangestring
<< std::setw(12) << spell_hunger_string(spell)
<< spell_difficulty(spell);
diff --git a/crawl-ref/source/stuff.cc b/crawl-ref/source/stuff.cc
index d1cb01d31a..1bbba85a91 100644
--- a/crawl-ref/source/stuff.cc
+++ b/crawl-ref/source/stuff.cc
@@ -377,7 +377,7 @@ static bool tag_follower_at(const coord_def &pos)
fmenv->flags |= MF_TAKING_STAIRS;
// Clear patrolling/travel markers.
- fmenv->patrol_point = coord_def(0, 0);
+ fmenv->patrol_point.reset();
fmenv->travel_path.clear();
fmenv->travel_target = MTRAV_NONE;