types.{addr*,label,{host,file,{absolute-,}path}name}: use isString

This commit is contained in:
tv 2016-06-13 01:40:57 +02:00
parent 0cfce6d18d
commit 3846e08de8

View file

@ -239,7 +239,7 @@ types // rec {
check = let check = let
IPv4address = let d = "([1-9]?[0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])"; in IPv4address = let d = "([1-9]?[0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])"; in
concatMapStringsSep "." (const d) (range 1 4); concatMapStringsSep "." (const d) (range 1 4);
in x: match IPv4address x != null; in x: isString x && match IPv4address x != null;
merge = mergeOneOption; merge = mergeOneOption;
}; };
addr6 = mkOptionType { addr6 = mkOptionType {
@ -247,7 +247,7 @@ types // rec {
check = let check = let
# TODO check IPv6 address harder # TODO check IPv6 address harder
IPv6address = "[0-9a-f.:]+"; IPv6address = "[0-9a-f.:]+";
in x: match IPv6address x != null; in x: isString x && match IPv6address x != null;
merge = mergeOneOption; merge = mergeOneOption;
}; };
@ -315,7 +315,7 @@ types // rec {
# RFC952, B. Lexical grammar, <hname> # RFC952, B. Lexical grammar, <hname>
hostname = mkOptionType { hostname = mkOptionType {
name = "hostname"; name = "hostname";
check = x: all label.check (splitString "." x); check = x: isString x && all label.check (splitString "." x);
merge = mergeOneOption; merge = mergeOneOption;
}; };
@ -324,14 +324,15 @@ types // rec {
label = mkOptionType { label = mkOptionType {
name = "label"; name = "label";
# TODO case-insensitive labels # TODO case-insensitive labels
check = x: match "[0-9A-Za-z]([0-9A-Za-z-]*[0-9A-Za-z])?" x != null; check = x: isString x
&& match "[0-9A-Za-z]([0-9A-Za-z-]*[0-9A-Za-z])?" x != null;
merge = mergeOneOption; merge = mergeOneOption;
}; };
# POSIX.12013, 3.278 Portable Filename Character Set # POSIX.12013, 3.278 Portable Filename Character Set
filename = mkOptionType { filename = mkOptionType {
name = "POSIX filename"; name = "POSIX filename";
check = x: match "([0-9A-Za-z._])[0-9A-Za-z._-]*" x != null; check = x: isString x && match "([0-9A-Za-z._])[0-9A-Za-z._-]*" x != null;
merge = mergeOneOption; merge = mergeOneOption;
}; };
@ -341,7 +342,7 @@ types // rec {
absolute-pathname = mkOptionType { absolute-pathname = mkOptionType {
name = "POSIX absolute pathname"; name = "POSIX absolute pathname";
check = x: let xs = splitString "/" x; xa = head xs; in check = x: let xs = splitString "/" x; xa = head xs; in
xa == "/" || (xa == "" && all filename.check (tail xs)); isString x && (xa == "/" || (xa == "" && all filename.check (tail xs)));
merge = mergeOneOption; merge = mergeOneOption;
}; };
@ -350,7 +351,7 @@ types // rec {
pathname = mkOptionType { pathname = mkOptionType {
name = "POSIX pathname"; name = "POSIX pathname";
check = x: let xs = splitString "/" x; in check = x: let xs = splitString "/" x; in
all filename.check (if head xs == "" then tail xs else xs); isString x && all filename.check (if head xs == "" then tail xs else xs);
merge = mergeOneOption; merge = mergeOneOption;
}; };