aboutsummaryrefslogtreecommitdiff
path: root/include/cru/platform/GraphBase.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'include/cru/platform/GraphBase.hpp')
-rw-r--r--include/cru/platform/GraphBase.hpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/include/cru/platform/GraphBase.hpp b/include/cru/platform/GraphBase.hpp
index 9f3f8393..186ee9d0 100644
--- a/include/cru/platform/GraphBase.hpp
+++ b/include/cru/platform/GraphBase.hpp
@@ -258,7 +258,7 @@ struct TextRange final {
gsl::index GetStart() const { return position; }
gsl::index GetEnd() const { return position + count; }
- void SetEnd(gsl::index new_end) { count = new_end - position; }
+ void AdjustEnd(gsl::index new_end) { count = new_end - position; }
TextRange Normalize() const {
auto result = *this;
@@ -269,6 +269,13 @@ struct TextRange final {
return result;
}
+ TextRange CoerceInto(gsl::index min, gsl::index max) const {
+ auto coerce = [min, max](gsl::index index) {
+ return index > max ? max : (index < min ? min : index);
+ };
+ return TextRange::FromTwoSides(coerce(GetStart()), coerce(GetEnd()));
+ }
+
gsl::index position = 0;
gsl::index count = 0;
};