View source with raw comments or as raw
    1/*  Part of SWI-Prolog
    2
    3    Author:        Jan Wielemaker
    4    E-mail:        J.Wielemaker@vu.nl
    5    WWW:           http://www.swi-prolog.org
    6    Copyright (c)  1985-2012, University of Amsterdam
    7                              VU University Amsterdam
    8    All rights reserved.
    9
   10    Redistribution and use in source and binary forms, with or without
   11    modification, are permitted provided that the following conditions
   12    are met:
   13
   14    1. Redistributions of source code must retain the above copyright
   15       notice, this list of conditions and the following disclaimer.
   16
   17    2. Redistributions in binary form must reproduce the above copyright
   18       notice, this list of conditions and the following disclaimer in
   19       the documentation and/or other materials provided with the
   20       distribution.
   21
   22    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   23    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   24    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
   25    FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
   26    COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
   27    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
   28    BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   29    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
   30    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   31    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
   32    ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   33    POSSIBILITY OF SUCH DAMAGE.
   34*/
   35
   36:- module(ctypes,
   37          [ is_alnum/1,
   38            is_alpha/1,
   39            is_ascii/1,
   40            is_cntrl/1,
   41            is_csym/1,
   42            is_csymf/1,
   43            is_digit/1,
   44            is_digit/3,
   45            is_endfile/1,
   46            is_endline/1,
   47            is_graph/1,
   48            is_lower/1,
   49            is_newline/1,
   50            is_newpage/1,
   51            is_paren/2,
   52            is_period/1,
   53            is_print/1,
   54            is_punct/1,
   55            is_quote/1,
   56            is_space/1,
   57            is_upper/1,
   58            is_white/1,
   59            to_lower/2,
   60            to_upper/2,
   61            upper_lower/2
   62          ]).

Character code classification

This file implements the functionality of the corresponding Quintus library based on SWI-Prolog's code_type/2 predicate. Please check the documentation of this predicate to find the definitions of the classes.

See also
- code_type/2
- char_type/2 */
   74is_alnum(C)   :- code_type(C, alnum).
   75is_alpha(C)   :- code_type(C, alpha).
   76is_ascii(C)   :- code_type(C, ascii).
   77is_cntrl(C)   :- code_type(C, cntrl).
   78is_csym(C)    :- code_type(C, csym).
   79is_csymf(C)   :- code_type(C, csymf).
   80is_digit(C)   :- code_type(C, digit).
   81is_graph(C)   :- code_type(C, graph).
   82is_lower(C)   :- code_type(C, lower).
   83is_upper(C)   :- code_type(C, upper).
   84is_period(C)  :- code_type(C, period).
   85is_endline(C) :- code_type(C, end_of_line).
   86is_print(C)   :- is_graph(C).
   87is_punct(C)   :- code_type(C, punct).
   88is_quote(C)   :- code_type(C, quote).
   89is_space(C)   :- code_type(C, space).
   90is_white(C)   :- code_type(C, white).
   91
   92is_endfile(-1).
   93is_newpage(12).                         % Control-L
   94is_newline(10).
 is_paren(?Open, ?Close) is semidet
True if Open is the open-parenthesis of Close.
  100is_paren(0'(, 0')).                     % Prolog is too good at this
  101is_paren(0'[, 0']).
  102is_paren(0'{, 0'}).
 to_lower(+U, -L) is det
Downcase a character code. If U is the character code of an uppercase character, unify L with the character code of the lowercase version. Else unify L with U.
  110to_lower(U, L) :-
  111    code_type(L, to_lower(U)).
 to_upper(+L, -U) is det
Upcase a character code. If L is the character code of a lowercase character, unify L with the character code of the uppercase version. Else unify U with L.
  119to_upper(L, U) :-
  120    code_type(U, to_upper(L)).
 upper_lower(?U, ?L) is det
True when U is the character code of an uppercase character and L is the character code of the corresponding lowercase character.
  128upper_lower(Upper, Lower) :-
  129    nonvar(Upper),
  130    !,
  131    code_type(Lower, lower(Upper)).
  132upper_lower(Upper, Lower) :-
  133    code_type(Upper, upper(Lower)).
 is_digit(+C, +Base, -Weight) is det
is_digit(-C, +Base, +Weight) is det
Succeeds if `C' is a digit using `Base' as base and `Weight' represents its value. Only the base-10 case is handled by code_type.
  142is_digit(C, Base, Weight) :-
  143    Base == 10,
  144    !,
  145    code_type(C, digit(Weight)).
  146is_digit(C, Base, Weight) :-
  147    between(2, 36, Base),
  148    succ(X, Base),
  149    between(0, X, Weight),
  150    is_digit(C, Weight).
  151
  152is_digit(C, Weight) :-
  153    Weight < 10,
  154    !,
  155    plus(Weight, 0'0, C).
  156is_digit(C, Weight) :-
  157    plus(Weight, 87, C),
  158    !.         /* `a`-10 */
  159is_digit(C, Weight) :-
  160    plus(Weight, 55, C).            /* `A`-10 */