segment_for_print Function

private function segment_for_print(seg) result(res)

Converts a segment to a printable string representation.

This function generates a string representation of the segment seg for printing purposes. It converts special segments to predefined strings like <ANY>, <LF>, etc., or generates a character range representation for segments with defined min and max values.

Note

This function contains magic strings, so in the near future we would like to extract it to forgex_parameter_m module and remove the magic strings.

Type Bound

segment_t

Arguments

Type IntentOptional Attributes Name
class(segment_t), intent(in) :: seg

Return Value character(len=:), allocatable


Source Code

   function segment_for_print (seg) result(res)
      use :: forgex_utf8_m
      implicit none
      class(segment_t), intent(in) :: seg
      character(:), allocatable :: res
      character(:), allocatable :: cache

      if (seg == SEG_ANY) then
         res = "<ANY>"

      else if (seg == SEG_TAB) then
         res = "<TAB>"
      else if (seg == segment_t(9, 10)) then
         res = "<TAB, LF>"
      else if (seg == segment_t(9, 11)) then
         res = "<TAB, LF, VT>"   
      else if (seg == segment_t(9, 12)) then
         res = "<TAB, LF, VT, FF>"   
      else if (seg == segment_t(9, 13)) then
         res = "<TAB, LF, VT, FF, CR>"

      else if (seg == SEG_LF) then
         res = "<LF>"
      else if (seg == segment_t(10, 11)) then
         res = "<LF, VT>"   
      else if (seg == segment_t(10, 12)) then
         res = "<LF, VT, FF>"   
      else if (seg == segment_t(10, 13)) then
         res = "<LF, VT, FF, CR>"  

      else if (seg == segment_t(11, 11)) then
         res = "<VT>"   
      else if (seg == segment_t(11, 12)) then
         res = "<VT, FF>"   
      else if (seg == segment_t(11, 13)) then
         res = "<VT, FF, CR>"

      else if (seg == SEG_FF) then
         res = "<FF>"
      else if (seg == segment_t(12, 13)) then
         res = "<FF, CR>"

      else if (seg == SEG_CR) then
         res = "<CR>"
      else if (seg == SEG_SPACE) then
         res = "<SPACE>"
      else if (seg == SEG_ZENKAKU_SPACE) then
         res = "<ZENKAKU SPACE>"
      else if (seg == SEG_EPSILON) then
         res = "?"
      else if (seg == SEG_INIT) then
         res = "<INIT>"
      else if (seg == SEG_EMPTY) then
         res = "<EMPTY>"
      else if (seg%min == seg%max) then
         res = char_utf8(seg%min)
      else if (seg%max == UTF8_CODE_MAX) then
         if (seg%min == ichar(' ')) then
            cache = "<SPACE>"
         else
            cache = '"'//char_utf8(seg%min)//'"'
         end if
         res = '['//cache//'-'//"<U+1FFFFF>"//']'
      else
         if (seg%min == ichar(' ')) then
            cache = "<SPACE>"
         else
            cache = '"'//char_utf8(seg%min)//'"'
         end if
         res = '['//cache//'-"'//char_utf8(seg%max)//'"]'
      end if

      !!
      !! @note This function contains magic strings, so in the near future we would like
      !! to extract it to `forgex_parameter_m` module and remove the magic strings.

   end function segment_for_print