From 99b168bf9580be20a153c1f32426c36842b2e406 Mon Sep 17 00:00:00 2001 From: "Adam D. Ruppe" Date: Sun, 27 Aug 2023 10:38:12 -0400 Subject: [PATCH] whitespace fixes --- core.d | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/core.d b/core.d index 02869e2..5d32925 100644 --- a/core.d +++ b/core.d @@ -900,11 +900,17 @@ unittest { +/ nothrow @safe @nogc pure inout(char)[] stripInternal(return inout(char)[] s) { + bool isAllWhitespace = true; foreach(i, char c; s) if(c != ' ' && c != '\t' && c != '\n' && c != '\r') { s = s[i .. $]; + isAllWhitespace = false; break; } + + if(isAllWhitespace) + return s[$..$]; + for(int a = cast(int)(s.length - 1); a > 0; a--) { char c = s[a]; if(c != ' ' && c != '\t' && c != '\n' && c != '\r') { @@ -916,15 +922,19 @@ inout(char)[] stripInternal(return inout(char)[] s) { return s; } +/// ditto nothrow @safe @nogc pure inout(char)[] stripRightInternal(return inout(char)[] s) { - for(int a = cast(int)(s.length - 1); a > 0; a--) { - char c = s[a]; + bool isAllWhitespace = true; + foreach_reverse(a, c; s) { if(c != ' ' && c != '\t' && c != '\n' && c != '\r') { s = s[0 .. a + 1]; + isAllWhitespace = false; break; } } + if(isAllWhitespace) + s = s[0..0]; return s;