ADJUSTR(3f) - [M_unicode:WHITESPACE] right-justify a string (LICENSE:MIT)
Synopsis
Characteristics
Description
Options
Result
Examples
See Also
Author
License
result = adjustr(string,glyphs)
elemental function adjustr(string)type(unicode_type) :: adjustr type(unicode_type),intent(in) :: string integer,intent(in),optional :: glyphs
o STRING is a string variable o GLYPHS is a default integer o the return value is a string variable
ADJUSTR(3) right-justifies a string by removing trailing spaces. Spaces are inserted at the start of the string as needed to retain the original length unless an explicit return length is specified by the GLYPHS parameter.
o STRING : the string to right-justify o GLYPHS : length in glyphs to extend to or truncate to
trailing spaces are removed and the same number of spaces are then inserted at the start of string.
sample program:
program demo_adjustr use M_unicode, only : ut=>unicode_type use M_unicode, only : adjustr, len use M_unicode, only : write(formatted) use M_unicode, only : assignment(=) implicit none type(ut) :: str type(ut),allocatable :: array(:) integer :: i character(len=*),parameter :: bracket=("[",DT,"]") ! call numberline(2) ! ! basic usage str = sample string write(*,bracket) str str = adjustr(str) write(*,bracket) str ! call numberline(5) ! ! elemental array=ut([character(len=50) :: & एक (ek) , & दो (do) , & तीन(teen) ]) ! ! print array unadjusted write(*,bracket)array !do i=1,size(array) ! write(*,(*(g0,1x)))array(i)%codepoint() !enddo ! note 50 bytes is not necessarily 50 glyphs write(*,(*(g0,1x)))length in glyphs=,len(array) write(*,(*(g0,1x)))length in bytes=,(len(array(i)%character()),i=1,size(array)) ! call numberline(5) ! ! print array right-justified write(*,bracket)adjustr(array) ! call numberline(5) ! ! print array right-justified specifying number of glyphs write(*,*)set to 50 write(*,bracket)adjustr(array,50) ! write(*,*)set to 60 call numberline(6) write(*,bracket)adjustr(array,60) write(*,*)set to 40 call numberline(4) write(*,bracket)adjustr(array,40) write(*,*)set to 10 call numberline(1) write(*,bracket)adjustr(array,10) write(*,*)set to 5 write(*,bracket)adjustr(array,5) write(*,*)set to 4 write(*,bracket)adjustr(array,4) write(*,*)set to 1 write(*,bracket)adjustr(array,1) contains ! subroutine numberline(ireps) integer,intent(in) :: ireps write(*,(1x,a))repeat(1234567890,ireps) end subroutine numberline end program demo_adjustrResults:
> 12345678901234567890 > [ sample string ] > [ sample string] > 12345678901234567890123456789012345678901234567890 > [ एक (ek) ] > [ दो (do) ] > [ तीन(teen) ] > length in glyphs= 46 46 44 > length in bytes= 50 50 50 > 12345678901234567890123456789012345678901234567890 > [ एक (ek)] > [ दो (do)] > [ तीन(teen)] > 12345678901234567890123456789012345678901234567890 > set to 50 > [ एक (ek)] > [ दो (do)] > [ तीन(teen)] > set to 60 > 123456789012345678901234567890123456789012345678901234567890 > [ एक (ek)] > [ दो (do)] > [ तीन(teen)] > set to 40 > 1234567890123456789012345678901234567890 > [ एक (ek)] > [ दो (do)] > [ तीन(teen)] > set to 10 > 1234567890 > [ एक (ek)] > [ दो (do)] > [ तीन(teen)] > set to 5 > [ (ek)] > [ (do)] > [teen)] > set to 4 > [(ek)] > [(do)] > [een)] > set to 1 > [)] > [)] > [)]
ADJUSTL(3), TRIM(3)
John S. Urban
