From c41e7e63a3d0a4ebe90a536d4c7e7956a3581f02 Mon Sep 17 00:00:00 2001 From: crupest Date: Sat, 12 Sep 2020 00:53:51 +0800 Subject: ... --- include/cru/platform/GraphBase.hpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'include/cru/platform/GraphBase.hpp') 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; }; -- cgit v1.2.3