ENHANCED: Much faster Base64 encoding/decoding, using partial_string/1 for a quick check.
:- use_module(library(iso_ext)).
:- use_module(library(error)).
:- use_module(library(lists)).
+:- use_module(library(iso_ext), [partial_string/1]).
fabricate_var_name(VarType, VarName, N) :-
char_code('A', AC),
@@ -235,10 +236,15 @@ chars_base64(Cs, Bs, Options) :-
; domain_error(charset, Charset, chars_base64/3)
),
( var(Cs) ->
- must_be(list, Bs),
- maplist(must_be(character), Bs),
+ must_be_characters(Bs),
'$chars_base64'(Cs, Bs, Padding, Charset)
- ; must_be(list, Cs),
- maplist(must_be(character), Cs),
+ ; must_be_characters(Cs),
'$chars_base64'(Cs, Bs, Padding, Charset)
).
+
+must_be_characters(Cs) :-
+ ( partial_string(Cs) ->
+ true
+ ; must_be(list, Cs),
+ maplist(must_be(character), Cs)
+ ).
