Manual Reference Pages  - expandtabs (3m_unicode)

NAME

EXPANDTABS(3f) - [M_unicode:WHITESPACE] function to expand tab characters (LICENSE:MIT)

CONTENTS

Synopsis
Description
Options
Returns
Examples
Author
License

SYNOPSIS

elemental function expandtabs(INSTR,TABSIZE) result(OUT)

     type(unicode_type),intent=(in)  :: INSTR
     integer,intent(in),optional     :: TAB_SIZE
     type(unicode_type)              :: OUT

DESCRIPTION

EXPANDTABS(3) expands tabs in INSTR to spaces in OUT. It assumes a tab is set every 8 characters by default. Trailing spaces are removed.

OPTIONS

instr Input line to remove tabs from
tab_size
  spacing between tab stops.

RETURNS

out Output string with tabs expanded.

EXAMPLES

Sample program:

    program demo_expandtabs
    use M_unicode, only : expandtabs, ch=>character, replace
    use M_unicode, only : assignment(=), ut=> unicode_type
    implicit none
    type(ut)                     :: in
    type(ut)                     :: inexpanded
    character(len=:),allocatable :: dat
    integer                      :: i
       dat=’  this is my string  ’
       ! change spaces to tabs to make a sample input
       do i=1,len(dat)
          if(dat(i:i) == ’ ’)dat(i:i)=char(9)
       enddo
       in=dat
       !
       inexpanded=expandtabs(in)
       write(*,’("[",a,"]")’)ch(inexpanded)
       inexpanded=replace(inexpanded,ut(’ ’),ut(’_’))
       write(*,’("[",a,"]")’)ch(inexpanded)
       !
       write(*,’("[",a,"]")’)ch(in%expandtabs())
       write(*,’("[",a,"]")’)ch(in%expandtabs(tab_size=8))
       write(*,’("[",a,"]")’)ch(in%expandtabs(tab_size=1))
       write(*,’("[",a,"]")’)ch(in%expandtabs(tab_size=0))
       !
    end program demo_expandtabs

Results:

    > [                this    is      my      string]
    > [________________this____is______my______string]
    > [                this    is      my      string]
    > [                this    is      my      string]
    > [  this is my string]
    > [thisismystring]

AUTHOR

John S. Urban

LICENSE

    MIT