len_trim_utf8 Function

public pure function len_trim_utf8(str) result(count)

This function calculates the length of a UTF-8 string excluding tailing spaces.

It takes a UTF-8 string as input and returns the number of characters in the string, ignoring any tailing whitespace characters.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: str

Return Value integer


Source Code

   pure function len_trim_utf8(str) result(count)
      implicit none
      character(*), intent(in) :: str
      integer :: i, inext, count

      ! Initialize
      i = 1
      count = 0

      ! Loop through the string until the end of the trimed string is reached.
      do while(i <= len_trim(str))
         inext = idxutf8(str, i) + 1   ! Get the index of the next UTF-8 character.
         count = count + 1             ! Increment the character count.
         i = inext                     ! Move to the next character.
      end do

   end function len_trim_utf8