aboutsummaryrefslogtreecommitdiff
path: root/src/fpm_strings.f90
diff options
context:
space:
mode:
authorLaurence Kedward <laurence.kedward@bristol.ac.uk>2021-07-16 11:07:16 +0100
committerGitHub <noreply@github.com>2021-07-16 11:07:16 +0100
commit68937a4eae6a71b74edbf762c574cc2dc22bb2d6 (patch)
treee61837e75eeb361af0c3624a7f28169a9d06bf60 /src/fpm_strings.f90
parent5617e65751193afb3c88fbc6cb8a32822ff52ffa (diff)
parent87271c5a55ad6412114c4b153c1a8d0bd37156f5 (diff)
downloadfpm-68937a4eae6a71b74edbf762c574cc2dc22bb2d6.tar.gz
fpm-68937a4eae6a71b74edbf762c574cc2dc22bb2d6.zip
Merge pull request #511 from urbanjost/warn_blank_name
check name used for package, executable, test, or example
Diffstat (limited to 'src/fpm_strings.f90')
-rw-r--r--src/fpm_strings.f9034
1 files changed, 34 insertions, 0 deletions
diff --git a/src/fpm_strings.f90 b/src/fpm_strings.f90
index 3d7d7b1..ee5c20a 100644
--- a/src/fpm_strings.f90
+++ b/src/fpm_strings.f90
@@ -20,6 +20,8 @@
!! - [[STRING_ARRAY_CONTAINS]] Check if array of **TYPE(STRING_T)** matches a particular **CHARACTER** string
!! - **OPERATOR(.IN.)** Check if array of **TYPE(STRING_T)** matches a particular **CHARACTER** string
!! - [[GLOB]] function compares text strings, one of which can have wildcards ('*' or '?').
+!! - [[IS_FORTRAN_NAME]] determine whether a string is an acceptable Fortran entity name
+!! - [[TO_FORTRAN_NAME]] replace allowed special but unusuable characters in names with underscore
!!### Miscellaneous
!! - [[LEN_TRIM]] Determine total trimmed length of **STRING_T** array
!! - [[FNV_1A]] Hash a **CHARACTER(*)** string of default kind or a **TYPE(STRING_T)** array
@@ -33,6 +35,7 @@ implicit none
private
public :: f_string, lower, split, str_ends_with, string_t
+public :: to_fortran_name, is_fortran_name
public :: string_array_contains, string_cat, len_trim, operator(.in.), fnv_1a
public :: replace, resize, str, join, glob
@@ -921,4 +924,35 @@ else
end if
end function
+!> Returns string with special characters replaced with an underscore.
+!! For now, only a hyphen is treated as a special character, but this can be
+!! expanded to other characters if needed.
+pure function to_fortran_name(string) result(res)
+ character(*), intent(in) :: string
+ character(len(string)) :: res
+ character, parameter :: SPECIAL_CHARACTERS(*) = ['-']
+ res = replace(string, SPECIAL_CHARACTERS, '_')
+end function to_fortran_name
+
+function is_fortran_name(line) result (lout)
+! determine if a string is a valid Fortran name ignoring trailing spaces
+! (but not leading spaces)
+ character(len=*),parameter :: int='0123456789'
+ character(len=*),parameter :: lower='abcdefghijklmnopqrstuvwxyz'
+ character(len=*),parameter :: upper='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
+ character(len=*),parameter :: allowed=upper//lower//int//'_'
+ character(len=*),intent(in) :: line
+ character(len=:),allocatable :: name
+ logical :: lout
+ name=trim(line)
+ if(len(name).ne.0)then
+ lout = .true. &
+ & .and. verify(name(1:1), lower//upper) == 0 &
+ & .and. verify(name,allowed) == 0 &
+ & .and. len(name) <= 63
+ else
+ lout = .false.
+ endif
+ end function is_fortran_name
+
end module fpm_strings