Commit 70b90cf4 authored by Henderson, Shane's avatar Henderson, Shane Committed by Graham, Aaron
Browse files

StingType partition method failed to perform as expected with a space as the delimiter

Fortran matched the space with the empty string and failed to accurate partition the string
parent f4bcaa77
......@@ -349,7 +349,7 @@ PURE FUNCTION partition(this,sep) RESULT(tokens)
TYPE(StringType) :: tokens(3)
INTEGER(SIK) :: sepPos
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
tokens(1) = this%s(1:sepPos-1)
tokens(3) = this%s(sepPos+LEN(SEP):LEN(this%s))
......@@ -378,7 +378,7 @@ PURE FUNCTION rPartition(this,sep) RESULT(tokens)
TYPE(StringType) :: tokens(3)
INTEGER(SIK) :: sepPos
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
tokens(1) = this%s(1:sepPos-1)
tokens(3) = this%s(sepPos+LEN(SEP):LEN(this%s))
......
......@@ -917,7 +917,20 @@ SUBROUTINE testStrFunct()
ASSERT_EQ(CHAR(str_list(2)),'---','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
!
SUBROUTINE testConstructor
TYPE(StringType) :: test0
TYPE(StringType),ALLOCATABLE :: test1(:)
......
Markdown is supported
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