Skip to content

Commit 2cb994d

Browse files
committed
add function to replace special characters to undercores
1 parent 7af51a6 commit 2cb994d

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

fpm/src/fpm_filesystem.f90

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ module fpm_filesystem
22
use fpm_environment, only: get_os_type, &
33
OS_UNKNOWN, OS_LINUX, OS_MACOS, OS_WINDOWS, &
44
OS_CYGWIN, OS_SOLARIS, OS_FREEBSD
5-
use fpm_strings, only: f_string, string_t, split
5+
use fpm_strings, only: f_string, replace, string_t, split
66
implicit none
77
private
88
public :: basename, canon_path, dirname, is_dir, join_path, number_of_rows, read_lines, list_files, env_variable, &
9-
mkdir, exists, get_temp_filename, windows_path, unix_path, getline, delete_file
9+
mkdir, exists, get_temp_filename, windows_path, unix_path, getline, delete_file, to_fortran_name
1010

1111
integer, parameter :: LINE_BUFFER_LEN = 1000
1212

@@ -465,4 +465,15 @@ subroutine delete_file(file)
465465
end subroutine delete_file
466466

467467

468+
pure function to_fortran_name(string) result(res)
469+
! Returns string with special characters replaced with an underscore.
470+
! For now, only a hyphen is treated as a special character, but this can be
471+
! expanded to other characters if needed.
472+
character(*), intent(in) :: string
473+
character(len(string)) :: res
474+
character, parameter :: SPECIAL_CHARACTERS(*) = ['-']
475+
res = replace(string, SPECIAL_CHARACTERS, '_')
476+
end function to_fortran_name
477+
478+
468479
end module fpm_filesystem

0 commit comments

Comments
 (0)