summaryrefslogtreecommitdiff
path: root/src/mbgl/text/tagged_string.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/text/tagged_string.cpp')
-rw-r--r--src/mbgl/text/tagged_string.cpp24
1 files changed, 20 insertions, 4 deletions
diff --git a/src/mbgl/text/tagged_string.cpp b/src/mbgl/text/tagged_string.cpp
index 851e011c4f..3755ad3a28 100644
--- a/src/mbgl/text/tagged_string.cpp
+++ b/src/mbgl/text/tagged_string.cpp
@@ -1,11 +1,12 @@
#include <mbgl/text/tagged_string.hpp>
+#include <mbgl/math/minmax.hpp>
#include <mbgl/util/i18n.hpp>
namespace mbgl {
-void TaggedString::addSection(const std::u16string& sectionText, double scale, FontStackHash fontStack) {
+void TaggedString::addSection(const std::u16string& sectionText, double scale, FontStack fontStack, const optional<FormattedSectionID>& id) {
styledText.first += sectionText;
- sections.emplace_back(scale, fontStack);
+ sections.emplace_back(scale, fontStack, id);
styledText.second.resize(styledText.first.size(), sections.size() - 1);
}
@@ -19,14 +20,14 @@ void TaggedString::trim() {
std::size_t trailingWhitespace = styledText.first.find_last_not_of(u" \t\n\v\f\r") + 1;
styledText.first = styledText.first.substr(beginningWhitespace, trailingWhitespace - beginningWhitespace);
- styledText.second = std::vector<uint8_t>(styledText.second.begin() + beginningWhitespace, styledText.second.begin() + trailingWhitespace);
+ styledText.second = std::vector<std::size_t>(styledText.second.begin() + beginningWhitespace, styledText.second.begin() + trailingWhitespace);
}
}
double TaggedString::getMaxScale() const {
double maxScale = 0.0;
for (std::size_t i = 0; i < styledText.first.length(); i++) {
- maxScale = std::max(maxScale, getSection(i).scale);
+ maxScale = util::max(maxScale, getSection(i).scale);
}
return maxScale;
}
@@ -36,4 +37,19 @@ void TaggedString::verticalizePunctuation() {
styledText.first = util::i18n::verticalizePunctuation(styledText.first);
}
+bool TaggedString::hasMultipleUniqueSections() const noexcept {
+ if (sections.size() < 2) {
+ return false;
+ }
+
+ const auto& id = sections.at(0).id;
+ for (std::size_t i = 1; i < sections.size(); ++i) {
+ if (id != sections.at(i).id) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
} // namespace mbgl