1 module fixedstring.fixedstringrange;
2 
3 package(fixedstring):
4 
5 struct FixedStringRange(DataType)
6 {
7 	private const(DataType)[] source;
8 	private size_t startIndex;
9 	private size_t length_;
10 	size_t length()
11 	{
12 		return length_;
13 	}
14 
15 	@disable this();
16 
17 	package this(in DataType[] source)
18 	{
19 		this.source = source;
20 		this.length_ = source.length;
21 	}
22 
23 	bool empty() const
24 	{
25 		return length_ == 0;
26 	}
27 
28 	DataType front()
29 	in (!empty)
30 	{
31 		return source[startIndex];
32 	}
33 
34 	void popFront()
35 	in (!empty)
36 	{
37 		++startIndex;
38 		--length_;
39 	}
40 
41 	typeof(this) save()
42 	{
43 		return this;
44 	}
45 
46 	DataType back()
47 	in (!empty)
48 	{
49 		return source[startIndex + (length_ - 1)];
50 	}
51 
52 	void popBack()
53 	in (!empty)
54 	{
55 		--length_;
56 	}
57 
58 	DataType opIndex(in size_t index)
59 	in (index < length_)
60 	{
61 		return source[startIndex + index];
62 	}
63 
64 	auto opSlice(in size_t first, in size_t last)
65 	in (first <= length_ && last <= length_)
66 	{
67 		return typeof(this)(source[(startIndex + first) .. (startIndex + last)]);
68 	}
69 }