This subroutine parses a pattern string for character class,
and outputs character_array_t
type array.
When it encounters invalid value along the way, it returns.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | str | |||
type(character_array_t), | intent(inout), | allocatable | :: | array(:) |
pure subroutine character_string_to_array(str, array) use :: forgex_parameters_m, only: INVALID_CHAR_INDEX use :: forgex_error_m use :: forgex_utf8_m, only: len_utf8, idxutf8 implicit none character(*), intent(in) :: str type(character_array_t), intent(inout), allocatable :: array(:) integer :: siz, ib, ie, j siz = len_utf8(str) if (siz < 1) return if (allocated(array)) deallocate(array) allocate(array(siz)) ib = 0 ie = 0 do j = 1, siz ib = ie + 1 ie = idxutf8(str, ib) if (ib == INVALID_CHAR_INDEX .or. ie == INVALID_CHAR_INDEX) return array(j)%c = str(ib:ie) end do end subroutine character_string_to_array