expand(3f) - [M_strings:NONALPHA] expand C-like escape sequences (LICENSE:PD)
Synopsis
Description
Examples
Author
License
function expand(line,escape) result(lineout)
character(len=*) :: line character(len=1),intent(in),optional :: escape character(len=:),allocatable :: lineout
EXPAND(3) expands sequences used to represent commonly used escape sequences or control characters. By default ...Escape sequences
\ backslash a alert (BEL) -- g is an alias for a b backspace c suppress further output e escape f form feed n new line r carriage return t horizontal tab v vertical tab oNNN byte with octal value NNN (3 digits) dNNN byte with decimal value NNN (3 digits) xHH byte with hexadecimal value HH (2 digits) -- h is an alias for xThe default escape character is the backslash, but this may be changed using the optional parameter ESCAPE.
Sample Program:
program demo_expand ! demonstrate filter to expand C-like escape sequences in input lines use M_strings, only : expand integer,parameter :: iwidth=1024 integer :: i character(len=iwidth),parameter :: input(*)=[ character(len=iwidth) :: & \e[H\e[2J,& ! home cursor and clear screen on ANSI terminals \tABC\tabc,& ! write some tabs in the output \tA\a,& ! ring bell at end if supported \nONE\nTWO\nTHREE,& ! place one word per line \#146;] write(*,(a))(trim(expand(input(i))),i=1,size(input)) end program demo_expandResults (with nonprintable characters shown visible):
> ^[[H^[[2J > ^IABC^Iabc > ^IA^G > > ONE > TWO > THREE > \
John S. Urban
Public Domain
Nemo Release 3.1 | expand (3m_strings) | January 10, 2025 |