aboutsummaryrefslogtreecommitdiff
path: root/src/fpm_strings.f90
diff options
context:
space:
mode:
authorLKedward <laurence.kedward@bristol.ac.uk>2021-07-16 15:24:25 +0100
committerLKedward <laurence.kedward@bristol.ac.uk>2021-07-16 15:24:25 +0100
commitf884bfd38a546dba12ccabcce8581e7bab29e51f (patch)
tree9c0f3822b59741f18cfb8feef02db7d27caf712d /src/fpm_strings.f90
parent53027990c205eb905ff534544f4752ea92e747d7 (diff)
parent68937a4eae6a71b74edbf762c574cc2dc22bb2d6 (diff)
downloadfpm-f884bfd38a546dba12ccabcce8581e7bab29e51f.tar.gz
fpm-f884bfd38a546dba12ccabcce8581e7bab29e51f.zip
Merge branch 'upstream_master' into file-listing
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 5a47311..ba76d15 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
@@ -34,6 +36,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
@@ -953,4 +956,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