diff --git a/src/icartt/dataset.py b/src/icartt/dataset.py index 660a2e9dfb5d218af8ca718116777d960ba88a8a..1528158734013c22172b05a39313f1faaddb41f6 100644 --- a/src/icartt/dataset.py +++ b/src/icartt/dataset.py @@ -348,7 +348,7 @@ class Variable: # Uppercase and lowercase ASCII alphanumeric characters # and underscores. - allAreAlphaOrUnderscore = all(utl.isAsciiAlphaOrUnderscore(x) for x in name) + allAreAlphaOrUnderscore = all(re.match("[a-zA-Z0-9_]", c) for c in name) # The first character must be a letter, firstIsAlpha = bool(re.match("[a-zA-Z]", name[0])) # and the name can be at most 31 characters in length. @@ -757,7 +757,7 @@ class Dataset: :return: is file name valid according to ICARTT standard? :rtype: bool """ - allAsciiAlpha = utl.isAsciiAlpha(name) + allAsciiAlpha = all(re.match("[a-zA-Z0-9-_.]", c) for c in name) lessThan128Characters = len(name) < 128 return allAsciiAlpha and lessThan128Characters and name.endswith(".ict") diff --git a/src/icartt/ictutils.py b/src/icartt/ictutils.py index 0f2066c72f2967922994143a415a2eba946467bc..f7f666c4fbfadf0d687261a167a30bbc81ed12b5 100644 --- a/src/icartt/ictutils.py +++ b/src/icartt/ictutils.py @@ -1,7 +1,5 @@ # -*- coding: utf-8 -*- -import re - class FilehandleWithLinecounter: """a file handle that counts the number of files that were read""" @@ -19,16 +17,6 @@ class FilehandleWithLinecounter: return dmp -def isAsciiAlphaOrUnderscore(x: str) -> bool: - """check if string x contains only characters from [a-zA-Z0-9_] regex""" - return re.match("[a-zA-Z0-9_]", x) - - -def isAsciiAlpha(x): - """check if string x contains only characters from [a-zA-Z0-9-_.] regex""" - return re.match("[a-zA-Z0-9-_.]", x) - - def extractVardesc(line_parts: list) -> str: """extract variable description from ict header line parts (splitted line)""" shortname, units, standardname, longname, *_ = line_parts + [None] * 3