For Development HEAD DRAFTSearch (procedure/syntax/module):

Next: , Previous: , Up: Library modules - SRFIs   [Contents][Index]

11.37 srfi.175 - ASCII character library

Module: srfi.175

This module provides a set of character/string utilities that deal with ASCII characters and codepoints. It is particulary useful for small Scheme implementations that only handles, and a portable code that only concerns, ASCII characters.

Since Gauche supports full Unicode, you may not need to use this module to write Gauche-specific code. This is mainly for the compatibility.

One of the characteristics of this module is that many procedures can take an integer in place of a character; an integer between 0 and 127 is interpreted as an ASCII codepoint. An integer outside the range is interpreted as an non-ASCII codepoint. Such argument is noted as char-or-code in the description. It is handy while you’re dealing with a binary file which may contain some ASCII text in it.

Function: ascii-codepoint? obj

[SRFI-175]{srfi.175} Returns #t iff obj is an exact integer between 0 and 127, inclusive.

Function: ascii-bytevecotr? obj

[SRFI-175]{srfi.175} Returns #t iff obj is a bytevector (u8vector) and all of its elements are between 0 and 127, inclusive.

Function: ascii-char? obj

[SRFI-175]{srfi.175} Returns #t iff obj is an ASCII character.

Function: ascii-string? obj

[SRFI-175]{srfi.175} Returns #t iff obj is a string and all of its elements are ASCII characters.

Function: ascii-control? char-or-code

[SRFI-175]{srfi.175} Returns #t iff char-or-code is in the range of ASCII control characters

(ascii-control? #\tab) ⇒ #t
(ascii-control? #\A)   ⇒ #f

(ascii-control? 127)   ⇒ #t
(ascii-control? 255)   ⇒ #f

Note: The accepted character range corresponds to char-set:ascii-control (see Predefined character sets).

Function: ascii-non-control? char-or-code

[SRFI-175]{srfi.175} Returns #t iff char-or-code is in the range of ASCII but not a control character.

Function: ascii-space-or-tab? char-or-code

[SRFI-175]{srfi.175} Returns #t iff char-or-code is a tab or a whitespace.

Function: ascii-other-graphic? char-or-code

[SRFI-175]{srfi.175} Returns #t iff char-or-code is in the range of ASCII graphic characters but not a letter nor a digit.

Note: The accepted character range corresponds to (char-set-difference char-set:ascii-graphic char-set:ascii-letter+digit) (see Predefined character sets).

Function: ascii-alphanumeric? char-or-code

[SRFI-175]{srfi.175} Returns #t iff char-or-code is in the ASCII alphabet or digit range.

Note: The accepted character range corresponds to char-set:ascii-letter+digit (see Predefined character sets).

Function: ascii-alphabetic? char-or-code

[SRFI-175]{srfi.175} Returns #t iff char-or-code is in the ASCII alphabet range.

Note: The accepted character range corresponds to char-set:ascii-letter (see Predefined character sets).

Function: ascii-numeric? char-or-code

[SRFI-175]{srfi.175} Returns #t iff char-or-code is in the ASCII digit range.

Note: The accepted character range corresponds to char-set:ascii-digit (see Predefined character sets).

Function: ascii-whitespace? char-or-code

[SRFI-175]{srfi.175} Returns #t iff char-or-code is one of the ASCII whitespaces.

Note: The accepted character range corresponds to char-set:ascii-whitespace (see Predefined character sets).

Function: ascii-upper-case? char-or-code
Function: ascii-lower-case? char-or-code

[SRFI-175]{srfi.175} Returns #t iff char-or-code is one of upper/lower case ASCII alphabets.

Note: The accepted character range corresponds to char-set:ascii-upper-case/char-set:ascii-lower-case (see Predefined character sets).

Function: ascii-ci=? char-or-code1 char-or-code2
Function: ascii-ci<? char-or-code1 char-or-code2
Function: ascii-ci<=? char-or-code1 char-or-code2
Function: ascii-ci>? char-or-code1 char-or-code2
Function: ascii-ci>=? char-or-code1 char-or-code2

[SRFI-175]{srfi.175} Each argument may be a character or a codepoint. If the argument falls into ASCII upper case letters, it is converted to the corresponding lower case letter codepoint, and then two are compared as codepoints. Two arguments don’t need to be of the same type.

It is allowed to pass non-ascii range; if it is a non-ASCII character, its codepoint of the native encoding is taken (no case-folding is considered), and compared as codepoints. Of course the result are not portable, except that any non-ASCII character has a codepoint greater than any ASCII characters.

Function: ascii-string-ci=? string1 string2
Function: ascii-string-ci<? string1 string2
Function: ascii-string-ci<=? string1 string2
Function: ascii-string-ci>? string1 string2
Function: ascii-string-ci>=? string1 string2

[SRFI-175]{srfi.175} Compares two strings with ASCII case folding. Argument strings may contain non-ASCII characters; such characters are compared without case folding.

Function: ascii-upcase char-or-code
Function: ascii-downcase char-or-code

[SRFI-175]{srfi.175} If the argument represents a ASCII upper/lower case letter, returns the corresponding lower/upper case character or codepoint. The type of the return value is the same as the argument. If the argument is a character or a codepoint other than that, it is returned as is.

Function: ascii-control->graphic char-or-code
Function: ascii-graphic->control char-or-code

[SRFI-175]{srfi.175} ASCII control characters (#\x00, #\x01 .. #\x1f, and #\x7f) are sometimes noted as ^@, ^A .. ^_, and ^?. These procedures converts the control character and corresponding graphical character (the one comes after ^), and vice versa. The type of the return value is the same as the argument.

If the argument isn’t an ASCII control character / a graphical character that corresponds to an ASCII control character, #f is returned.

Function: ascii-mirror-bracket char-or-code

[SRFI-175]{srfi.175} There are four pairs of brackets in ASCII: ( and ), { and }, [ and ], and < and >. If char-or-code is either one of these eight chars or codepoints, returns the corresponding bracket. The type of the return value is the same as the argument.

If the argument is a char or a codepoint other than those brackets, #f is returned.

Function: ascii-nth-digit n

[SRFI-175]{srfi.175} Returns a digit character representing the number n. If n is not an exact integer between 0 and 9, inclusive, #f is returned.

(ascii-nth-digit 3) ⇒ #\3

See also integer->digit (see Characters).

Function: ascii-nth-upper-case n
Function: ascii-nth-lower-case n

[SRFI-175]{srfi.175} Returns (modulo n 26)-th character of upper/lower case ASCII alphabet.

(ascii-nth-upper-case 0) ⇒ #\A
(ascii-nth-lower-case 1) ⇒ #\b

(ascii-nth-upper-case 25) ⇒ #\Z
(ascii-nth-lower-case 26) ⇒ #\a

See also integer->digit (see Characters).

Function: ascii-digit-value char-or-code limit

[SRFI-175]{srfi.175} If char-or-code represents an ASCII decimal digits and the corresponding number is less than limit, returns the number. Otherwise, returns #f.

(ascii-digit-value #\5 10) ⇒ 5
(ascii-digit-value #\9 8)  ⇒ #f

(ascii-digit-value 48 10)  ⇒ 0

See also digit->integer (see Characters).

Function: ascii-upper-case-value char-or-code offset limit
Function: ascii-lower-case-value char-or-code offset limit

[SRFI-175]{srfi.175} If char-or-code is n-th ASCII upper/lower case alphabet, and n is less than limit, returns (+ n offset). Otherwise returns #f.

(ascii-upper-case-value #\E 10 6) ⇒ 14
(ascii-lower-case-value #\z 0 26) ⇒ 25

See also digit->integer (see Characters).


Next: , Previous: , Up: Library modules - SRFIs   [Contents][Index]


For Development HEAD DRAFTSearch (procedure/syntax/module):
DRAFT