symbol_to_segment Function

public pure function symbol_to_segment(symbol) result(res)

This function convert an input symbol into the segment corresponding it.

Arguments

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

Return Value type(segment_t)


Source Code

   pure function symbol_to_segment(symbol) result(res)
      use :: forgex_utf8_m
      implicit none
      character(*), intent(in) :: symbol
      type(segment_t)          :: res

      integer(int32) :: i, i_end, code

      ! If `symbol` is a empty character, return SEG_EMPTY
      if (symbol == char(0)) then
         res = SEG_EMPTY
         return
      else if (symbol == char(32)) then
         res = SEG_SPACE
         return
      end if

      ! Initialize indices
      i = 1
      i_end = idxutf8(symbol, i)

      ! Get the code point of the input character.
      code = ichar_utf8(symbol(i:i_end))

      ! Create a segment corresponding to the code, and return it.
      res = segment_t(code, code)
   end function symbol_to_segment