From 8f7187dbca21d4c65b6a7aa28a694fb7ddfbced0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20R=C3=BCger?= Date: Tue, 21 Jan 2020 14:46:47 +0100 Subject: [PATCH] ftlString: made lower/upper/(l|r)strip elemental --- src/ftlString.F90 | 24 ++++++++++++------------ tests/ftlStringTests.F90 | 23 +++++++++++++++++++++++ 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/src/ftlString.F90 b/src/ftlString.F90 index 391a2c6..a3c5bbd 100644 --- a/src/ftlString.F90 +++ b/src/ftlString.F90 @@ -1653,7 +1653,7 @@ logical function EndsWithArray(self, postfixes) ! specifying the set of characters to be removed. If chars is omitted it defaults to removing whitespace. The chars ! argument is not a prefix or suffix; rather, all combinations of its values are stripped. ! - type(ftlString) function StripWhitespace(self) result(stripped) + elemental type(ftlString) function StripWhitespace(self) result(stripped) class(ftlString), intent(in) :: self integer :: first, last @@ -1669,7 +1669,7 @@ type(ftlString) function StripWhitespace(self) result(stripped) end function ! - type(ftlString) function StripRaw(self, chars) result(stripped) + elemental type(ftlString) function StripRaw(self, chars) result(stripped) class(ftlString), intent(in) :: self character(len=*), intent(in) :: chars @@ -1686,7 +1686,7 @@ type(ftlString) function StripRaw(self, chars) result(stripped) end function ! - type(ftlString) function StripString(self, chars) result(stripped) + elemental type(ftlString) function StripString(self, chars) result(stripped) class(ftlString), intent(in) :: self type(ftlString), intent(in) :: chars @@ -1699,7 +1699,7 @@ type(ftlString) function StripString(self, chars) result(stripped) ! of characters to be removed. If chars is omitted it defaults to removing whitespace. The chars argument is not a ! prefix or suffix; rather, all combinations of its values are stripped. ! - type(ftlString) function RStripWhitespace(self) result(stripped) + elemental type(ftlString) function RStripWhitespace(self) result(stripped) class(ftlString), intent(in) :: self integer :: last @@ -1709,7 +1709,7 @@ type(ftlString) function RStripWhitespace(self) result(stripped) end function ! - type(ftlString) function RStripRaw(self, chars) result(stripped) + elemental type(ftlString) function RStripRaw(self, chars) result(stripped) class(ftlString), intent(in) :: self character(len=*), intent(in) :: chars @@ -1720,7 +1720,7 @@ type(ftlString) function RStripRaw(self, chars) result(stripped) end function ! - type(ftlString) function RStripString(self, chars) result(stripped) + elemental type(ftlString) function RStripString(self, chars) result(stripped) class(ftlString), intent(in) :: self type(ftlString), intent(in) :: chars @@ -1733,7 +1733,7 @@ type(ftlString) function RStripString(self, chars) result(stripped) ! characters to be removed. If omitted or None, the chars argument defaults to removing whitespace. The chars ! argument is not a prefix; rather, all combinations of its values are stripped: ! - type(ftlString) function LStripWhitespace(self) result(stripped) + elemental type(ftlString) function LStripWhitespace(self) result(stripped) class(ftlString), intent(in) :: self integer :: first @@ -1748,7 +1748,7 @@ type(ftlString) function LStripWhitespace(self) result(stripped) end function ! - type(ftlString) function LStripRaw(self, chars) result(stripped) + elemental type(ftlString) function LStripRaw(self, chars) result(stripped) class(ftlString), intent(in) :: self character(len=*), intent(in) :: chars @@ -1764,7 +1764,7 @@ type(ftlString) function LStripRaw(self, chars) result(stripped) end function ! - type(ftlString) function LStripString(self, chars) result(stripped) + elemental type(ftlString) function LStripString(self, chars) result(stripped) class(ftlString), intent(in) :: self type(ftlString), intent(in) :: chars @@ -1813,7 +1813,7 @@ pure integer function FindRaw(self, sub, begin, end) result(idx) ! Return a copy of the string with all the cased characters converted to uppercase/lowercase. ! - type(ftlString) function Upper(self) + elemental type(ftlString) function Upper(self) class(ftlString), intent(in) :: self integer :: idx, ascii @@ -1826,7 +1826,7 @@ type(ftlString) function Upper(self) end function ! - type(ftlString) function Lower(self) + elemental type(ftlString) function Lower(self) class(ftlString), intent(in) :: self integer :: idx, ascii @@ -1843,7 +1843,7 @@ type(ftlString) function Lower(self) ! Return true if there are only whitespace characters in the string and there is at least one character, false otherwise. ! - logical function IsSpace(self) + elemental logical function IsSpace(self) class(ftlString), intent(in) :: self IsSpace = (len(self) > 0 .and. verify(self, FTL_STRING_WHITESPACE) == 0) diff --git a/tests/ftlStringTests.F90 b/tests/ftlStringTests.F90 index 96105e1..ec3fca3 100644 --- a/tests/ftlStringTests.F90 +++ b/tests/ftlStringTests.F90 @@ -83,6 +83,7 @@ subroutine ftlStringTests call testStrip call testRStrip call testLStrip + call testStripArray call testUpperLower call testIsSpace call testReplace @@ -1375,13 +1376,35 @@ subroutine testLStrip end subroutine + subroutine testStripArray + type(ftlString) :: s + type(ftlString), allocatable :: words(:) + + s = '[angstrom] [bohr] [z-matrix] ' + words = s%Split() + words = words%Strip('[]') + + ASSERT(words(1) == 'angstrom') + ASSERT(words(2) == 'bohr') + ASSERT(words(3) == 'z-matrix') + + end subroutine + + subroutine testUpperLower type(ftlString) :: s + type(ftlString), allocatable :: words(:) s = 'This is .A. [test]!' ASSERT(s%Upper() == 'THIS IS .A. [TEST]!') ASSERT(s%Lower() == 'this is .a. [test]!') + words = s%Split() + ASSERT(any(words%Upper() == 'IS')) + ASSERT(.not.any(words%Upper() == 'MISSING')) + ASSERT(any(words%Lower() == 'is')) + ASSERT(.not.any(words%Lower() == 'missing')) + s = FTL_STRING_DIGITS//FTL_STRING_LOWERCASE//FTL_STRING_WHITESPACE//FTL_STRING_PUNCTUATION ASSERT(s%Upper() == FTL_STRING_DIGITS//FTL_STRING_UPPERCASE//FTL_STRING_WHITESPACE//FTL_STRING_PUNCTUATION)