Skip to content

Commit

Permalink
ftlString: made lower/upper/(l|r)strip elemental
Browse files Browse the repository at this point in the history
  • Loading branch information
robertrueger committed Jan 21, 2020
1 parent ae537ca commit 8f7187d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/ftlString.F90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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

Expand All @@ -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
Expand All @@ -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

Expand All @@ -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

Expand All @@ -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
Expand All @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down
23 changes: 23 additions & 0 deletions tests/ftlStringTests.F90
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ subroutine ftlStringTests
call testStrip
call testRStrip
call testLStrip
call testStripArray
call testUpperLower
call testIsSpace
call testReplace
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 8f7187d

Please sign in to comment.