From 07c7bb88a95d2bfac7cab8df92e5b167dce5eaf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Tue, 22 Oct 2019 11:04:58 +0200 Subject: [PATCH] Make the range returned by bySegment2 a Voldemort type. Declaring it as a public symbol just introduces API maintenance burden without a real benefit. --- source/vibe/core/path.d | 110 ++++++++++++++++++++-------------------- 1 file changed, 55 insertions(+), 55 deletions(-) diff --git a/source/vibe/core/path.d b/source/vibe/core/path.d index d17eea5..2fc4111 100644 --- a/source/vibe/core/path.d +++ b/source/vibe/core/path.d @@ -502,59 +502,6 @@ struct GenericPath(F) { } } - /** Represents a path as an forward range of `Segment2`s. - - Note that in contrast to `PathRange`, this range allows pure `@nogc` - iteration over encoded path segments. - */ - static struct PathRange2 { - import std.traits : ReturnType; - - private { - string m_path; - Segment2 m_front; - } - - private this(string path) - { - m_path = path; - if (m_path.length) { - auto ap = Format.getAbsolutePrefix(m_path); - if (ap.length && !Format.isSeparator(ap[0])) - m_front = Segment2.fromTrustedEncodedString(null, '/'); - else readFront(); - } - } - - @property bool empty() const nothrow @nogc { return m_path.length == 0 && m_front == Segment2.init; } - - @property PathRange2 save() { return this; } - - @property Segment2 front() { return m_front; } - - void popFront() - nothrow { - assert(m_front != Segment2.init); - if (m_path.length) readFront(); - else m_front = Segment2.init; - } - - private void readFront() - { - auto n = Format.getFrontNode(m_path); - m_path = m_path[n.length .. $]; - - char sep = '\0'; - if (Format.isSeparator(n[$-1])) { - sep = n[$-1]; - n = n[0 .. $-1]; - } - m_front = Segment2.fromTrustedEncodedString(n, sep); - assert(m_front != Segment2.init); - } - } - - private { string m_path; } @@ -662,8 +609,61 @@ struct GenericPath(F) { @property PathRange bySegment() const { return PathRange(m_path); } - /// Iterates over the path by `Segment`. - @property PathRange2 bySegment2() const { return PathRange2(m_path); } + /** Iterates over the individual segments of the path. + + Returns a forward range of `Segment2`s. + */ + @property auto bySegment2() + const { + static struct R { + import std.traits : ReturnType; + + private { + string m_path; + Segment2 m_front; + } + + private this(string path) + { + m_path = path; + if (m_path.length) { + auto ap = Format.getAbsolutePrefix(m_path); + if (ap.length && !Format.isSeparator(ap[0])) + m_front = Segment2.fromTrustedEncodedString(null, '/'); + else readFront(); + } + } + + @property bool empty() const nothrow @nogc { return m_path.length == 0 && m_front == Segment2.init; } + + @property R save() { return this; } + + @property Segment2 front() { return m_front; } + + void popFront() + nothrow { + assert(m_front != Segment2.init); + if (m_path.length) readFront(); + else m_front = Segment2.init; + } + + private void readFront() + { + auto n = Format.getFrontNode(m_path); + m_path = m_path[n.length .. $]; + + char sep = '\0'; + if (Format.isSeparator(n[$-1])) { + sep = n[$-1]; + n = n[0 .. $-1]; + } + m_front = Segment2.fromTrustedEncodedString(n, sep); + assert(m_front != Segment2.init); + } + } + + return R(m_path); + } /// unittest {