Commit 158950c2 authored by Graham, Aaron's avatar Graham, Aaron
Browse files

Merge branch 'stringPartFix' into 'master'

Changes the way an empty string is checked

See merge request futility/Futility!355
parents f4bcaa77 70b90cf4
Pipeline #173117 passed with stage
in 2 minutes and 45 seconds
...@@ -349,7 +349,7 @@ PURE FUNCTION partition(this,sep) RESULT(tokens) ...@@ -349,7 +349,7 @@ PURE FUNCTION partition(this,sep) RESULT(tokens)
TYPE(StringType) :: tokens(3) TYPE(StringType) :: tokens(3)
INTEGER(SIK) :: sepPos INTEGER(SIK) :: sepPos
IF(ALLOCATED(this%s)) THEN IF(ALLOCATED(this%s)) THEN
sepPos = MERGE(0,INDEX(this%s,sep),sep == '') sepPos = MERGE(0,INDEX(this%s,sep),LEN(sep) == 0_SIK)
IF(sepPos > 0) THEN IF(sepPos > 0) THEN
tokens(1) = this%s(1:sepPos-1) tokens(1) = this%s(1:sepPos-1)
tokens(3) = this%s(sepPos+LEN(SEP):LEN(this%s)) tokens(3) = this%s(sepPos+LEN(SEP):LEN(this%s))
...@@ -378,7 +378,7 @@ PURE FUNCTION rPartition(this,sep) RESULT(tokens) ...@@ -378,7 +378,7 @@ PURE FUNCTION rPartition(this,sep) RESULT(tokens)
TYPE(StringType) :: tokens(3) TYPE(StringType) :: tokens(3)
INTEGER(SIK) :: sepPos INTEGER(SIK) :: sepPos
IF(ALLOCATED(this%s)) THEN IF(ALLOCATED(this%s)) THEN
sepPos = MERGE(0,INDEX(this%s,sep,.TRUE.),sep == '') sepPos = MERGE(0,INDEX(this%s,sep,.TRUE.),LEN(sep) == 0_SIK)
IF(sepPos > 0) THEN IF(sepPos > 0) THEN
tokens(1) = this%s(1:sepPos-1) tokens(1) = this%s(1:sepPos-1)
tokens(3) = this%s(sepPos+LEN(SEP):LEN(this%s)) tokens(3) = this%s(sepPos+LEN(SEP):LEN(this%s))
......
...@@ -917,7 +917,20 @@ SUBROUTINE testStrFunct() ...@@ -917,7 +917,20 @@ SUBROUTINE testStrFunct()
ASSERT_EQ(CHAR(str_list(2)),'---','string with multiple delimter found') ASSERT_EQ(CHAR(str_list(2)),'---','string with multiple delimter found')
ASSERT_EQ(CHAR(str_list(3)),'','string with multiple delimter found') ASSERT_EQ(CHAR(str_list(3)),'','string with multiple delimter found')
str = 'abc def ghi'
str_list = str%partition(' ')
ASSERT_EQ(SIZE(str_list),3,'string with multiple delimter found')
ASSERT_EQ(CHAR(str_list(1)),'abc','string with multiple delimter found')
ASSERT_EQ(CHAR(str_list(2)),' ','string with multiple delimter found')
ASSERT_EQ(CHAR(str_list(3)),'def ghi','string with multiple delimter found')
str_list = str%rPartition(' ')
ASSERT_EQ(SIZE(str_list),3,'string with multiple delimter found')
ASSERT_EQ(CHAR(str_list(1)),'abc def','string with multiple delimter found')
ASSERT_EQ(CHAR(str_list(2)),' ','string with multiple delimter found')
ASSERT_EQ(CHAR(str_list(3)),'ghi','string with multiple delimter found')
ENDSUBROUTINE testStrFunct ENDSUBROUTINE testStrFunct
!
SUBROUTINE testConstructor SUBROUTINE testConstructor
TYPE(StringType) :: test0 TYPE(StringType) :: test0
TYPE(StringType),ALLOCATABLE :: test1(:) TYPE(StringType),ALLOCATABLE :: test1(:)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment