Skip to content

Commit e4255a3

Browse files
committed
documented padl and padr functions
1 parent bf33954 commit e4255a3

File tree

1 file changed

+108
-0
lines changed

1 file changed

+108
-0
lines changed

doc/specs/stdlib_strings.md

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,3 +328,111 @@ program demo_find
328328
329329
end program demo_find
330330
```
331+
332+
333+
<!-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -->
334+
### `padl`
335+
336+
#### Description
337+
338+
Returns a string of length `output_length` left padded with `pad_with` character if it is provided, otherwise with `" "` (1 whitespace).
339+
If `output_length` is less than or equal to the length of `string`, padding is not performed.
340+
341+
#### Syntax
342+
343+
`string = [[stdlib_strings(module):padl(interface)]] (string, output_length [, pad_with])`
344+
345+
#### Status
346+
347+
Experimental
348+
349+
#### Class
350+
351+
Pure function
352+
353+
#### Argument
354+
355+
- `string`: Character scalar or [[stdlib_string_type(module):string_type(type)]].
356+
This argument is intent(in).
357+
- `output_length`: integer.
358+
This argument is intent(in).
359+
- `pad_with`: Character scalar of length 1.
360+
This argument is intent(in) and optional.
361+
362+
#### Result value
363+
364+
The result is of the same type as `string`.
365+
366+
#### Example
367+
368+
```fortran
369+
program demo_padl
370+
use stdlib_string_type, only: string_type, assignment(=)
371+
use stdlib_strings, only : padl
372+
implicit none
373+
string_type :: string
374+
375+
string = "left pad this string"
376+
! string <-- "left pad this string"
377+
378+
print *, padl(string, 25, "$") ! "$$$$$left pad this string"
379+
380+
string = padl(string, 25)
381+
! string <-- " left pad this string"
382+
383+
end program demo_padl
384+
```
385+
386+
387+
<!-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -->
388+
### `padr`
389+
390+
#### Description
391+
392+
Returns a string of length `output_length` right padded with `pad_with` character if it is provided, otherwise with `" "` (1 whitespace).
393+
If `output_length` is less than or equal to the length of `string`, padding is not performed.
394+
395+
#### Syntax
396+
397+
`string = [[stdlib_strings(module):padr(interface)]] (string, output_length [, pad_with])`
398+
399+
#### Status
400+
401+
Experimental
402+
403+
#### Class
404+
405+
Pure function
406+
407+
#### Argument
408+
409+
- `string`: Character scalar or [[stdlib_string_type(module):string_type(type)]].
410+
This argument is intent(in).
411+
- `output_length`: integer.
412+
This argument is intent(in).
413+
- `pad_with`: Character scalar of length 1.
414+
This argument is intent(in) and optional.
415+
416+
#### Result value
417+
418+
The result is of the same type as `string`.
419+
420+
#### Example
421+
422+
```fortran
423+
program demo_padr
424+
use stdlib_string_type, only: string_type, assignment(=)
425+
use stdlib_strings, only : padr
426+
implicit none
427+
string_type :: string
428+
429+
string = "right pad this string"
430+
! string <-- "right pad this string"
431+
432+
print *, padr(string, 25, "$") ! "right pad this string$$$$"
433+
434+
string = padr(string, 25)
435+
! string <-- "right pad this string "
436+
437+
end program demo_padr
438+
```

0 commit comments

Comments
 (0)