]> Repositorios git - scryer-prolog.git/commitdiff
ADDED: octet_character and octet_chars, testing for strings that represent bytes.
authorMarkus Triska <[email protected]>
Mon, 22 Aug 2022 19:54:03 +0000 (21:54 +0200)
committerMark Thom <[email protected]>
Thu, 27 Oct 2022 05:36:07 +0000 (23:36 -0600)
src/lib/error.pl

index 4c5af7c2354ca728870b4be9d651b59eeb81fd52..04b2868143cbe53fd6da58a879ce4b9b283919a1 100644 (file)
@@ -35,6 +35,8 @@
        - in_character
        - integer
        - list
+       - octet_character
+       - octet_chars
        - term
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
 
@@ -63,6 +65,17 @@ must_be_(chars, Ls) :-
             true
         ;   all_characters(Ls)
         ).
+must_be_(octet_character, C) :-
+        must_be(character, C),
+        (   octet_character(C) -> true
+        ;   domain_error(octet_character, C, must_be/2)
+        ).
+must_be_(octet_chars, Cs) :-
+        must_be(chars, Cs),
+        (   '$first_non_octet'(Cs, C) ->
+            domain_error(octet_character, C, must_be/2)
+        ;   true
+        ).
 must_be_(list, Term)    :- check_(error:ilist, list, Term).
 must_be_(type, Term)    :- check_(error:type, type, Term).
 must_be_(boolean, Term) :- check_(error:boolean, boolean, Term).
@@ -94,6 +107,10 @@ character(C) :-
         atom(C),
         atom_length(C, 1).
 
+octet_character(C) :-
+        char_code(C, Code),
+        0 =< Code, Code =< 0xff.
+
 in_character(C) :-
         (   character(C)
         ;   C == end_of_file
@@ -111,6 +128,8 @@ type(integer).
 type(atom).
 type(character).
 type(in_character).
+type(octet_character).
+type(octet_chars).
 type(chars).
 type(list).
 type(var).
@@ -147,6 +166,17 @@ can_(chars, Ls)     :-
         ;   can_be(list, Ls),
             can_be_chars(Ls)
         ).
+can_(octet_character, C) :-
+        (   octet_character(C) -> true
+        ;   domain_error(octet_character, C, can_be/2)
+        ).
+can_(octet_chars, Cs) :-
+        can_be(chars, Cs),
+        (   '$skip_max_list'(_, _, Cs, []), % temporarily turn Cs into a list
+            '$first_non_octet'(Cs, C) ->
+            domain_error(octet_character, C, can_be/2)
+        ;   true
+        ).
 can_(list, Term)    :- list_or_partial_list(Term).
 can_(boolean, Term) :- boolean(Term).
 can_(term, Term)    :-