1
0
mirror of https://github.com/cc65/cc65.git synced 2025-01-11 11:30:13 +00:00

Use constants for the bits in the _ctype array.

git-svn-id: svn://svn.cc65.org/cc65/trunk@865 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz 2001-09-08 14:00:41 +00:00
parent d799cc283f
commit def6300556
13 changed files with 55 additions and 27 deletions

28
libsrc/common/ctype.inc Normal file
View File

@ -0,0 +1,28 @@
;
; Definitions for the character type tables
;
; Ullrich von Bassewitz, 08.09.2001
;
; Make the __ctype table an exported/imported symbol
.global __ctype
; Define bitmapped constants for the table entries
CT_LOWER = $01 ; 0 - Lower case char
CT_UPPER = $02 ; 1 - Upper case char
CT_DIGIT = $04 ; 2 - Numeric digit
CT_XDIGIT = $08 ; 3 - Hex digit (both, lower and upper)
CT_CTRL = $10 ; 4 - Control character
CT_SPACE = $20 ; 5 - The space character itself
CT_OTHER_WS = $40 ; 6 - Other whitespace ('\f', '\n', '\r', '\t' and '\v')
CT_SPACE_TAB = $80 ; 7 - Space or tab character
; Combined stuff
CT_ALNUM = (CT_LOWER | CT_UPPER | CT_DIGIT)
CT_ALPHA = (CT_LOWER | CT_UPPER)
CT_CTRL_SPACE = (CT_CTRL | CT_SPACE)
CT_NOT_PUNCT = (CT_SPACE | CT_CTRL | CT_DIGIT | CT_UPPER | CT_LOWER)

View File

@ -5,14 +5,14 @@
;
.export _isalnum
.import __ctype
.include "ctype.inc"
_isalnum:
cpx #$00 ; Char range ok?
bne @L1 ; Jump if no
tay
lda __ctype,y ; Get character classification
and #$07 ; Mask character/digit bits
and #CT_ALNUM ; Mask character/digit bits
rts
@L1: lda #$00 ; Return false

View File

@ -5,14 +5,14 @@
;
.export _isalpha
.import __ctype
.include "ctype.inc"
_isalpha:
cpx #$00 ; Char range ok?
bne @L1 ; Jump if no
tay
lda __ctype,y ; Get character classification
and #$03 ; Mask character bits
and #CT_ALPHA ; Mask character bits
rts
@L1: lda #$00 ; Return false

View File

@ -7,14 +7,14 @@
;
.export _isblank
.import __ctype
.include "ctype.inc"
_isblank:
cpx #$00 ; Char range ok?
bne @L1 ; Jump if no
tay
lda __ctype,y ; Get character classification
and #$80 ; Mask blank bit
and #CT_SPACE_TAB ; Mask blank bit
rts
@L1: lda #$00 ; Return false

View File

@ -5,14 +5,14 @@
;
.export _iscntrl
.import __ctype
.include "ctype.inc"
_iscntrl:
cpx #$00 ; Char range ok?
bne @L1 ; Jump if no
tay
lda __ctype,y ; Get character classification
and #$10 ; Mask control character bit
and #CT_CTRL ; Mask control character bit
rts
@L1: lda #$00 ; Return false

View File

@ -5,14 +5,14 @@
;
.export _isdigit
.import __ctype
.include "ctype.inc"
_isdigit:
cpx #$00 ; Char range ok?
bne @L1 ; Jump if no
tay
lda __ctype,y ; Get character classification
and #$04 ; Mask digit bit
and #CT_DIGIT ; Mask digit bit
rts
@L1: lda #$00 ; Return false

View File

@ -5,15 +5,15 @@
;
.export _isgraph
.import __ctype
.include "ctype.inc"
_isgraph:
cpx #$00 ; Char range ok?
bne @L1 ; Jump if no
tay
lda __ctype,y ; Get character classification
eor #$30 ; NOT control and NOT space
and #$30 ; Mask character bits
eor #CT_CTRL_SPACE ; NOT control and NOT space
and #CT_CTRL_SPACE ; Mask character bits
rts
@L1: lda #$00 ; Return false

View File

@ -5,14 +5,14 @@
;
.export _islower
.import __ctype
.include "ctype.inc"
_islower:
cpx #$00 ; Char range ok?
bne @L1 ; Jump if no
tay
lda __ctype,y ; Get character classification
and #$01 ; Mask lower char bit
and #CT_LOWER ; Mask lower char bit
rts
@L1: lda #$00 ; Return false

View File

@ -5,15 +5,15 @@
;
.export _isprint
.import __ctype
.include "ctype.inc"
_isprint:
cpx #$00 ; Char range ok?
bne @L1 ; Jump if no
tay
lda __ctype,y ; Get character classification
eor #$10 ; NOT a control char
and #$10 ; Mask control char bit
eor #CT_CTRL ; NOT a control char
and #CT_CTRL ; Mask control char bit
rts
@L1: lda #$00 ; Return false

View File

@ -5,15 +5,15 @@
;
.export _ispunct
.import __ctype
.include "ctype.inc"
_ispunct:
cpx #$00 ; Char range ok?
bne @L1 ; Jump if no
tay
lda __ctype,y ; Get character classification
eor #$37 ; NOT (space | control | digit | char)
and #$37 ; Mask relevant bits
eor #CT_NOT_PUNCT ; NOT (space | control | digit | alpha)
and #CT_NOT_PUNCT ; Mask relevant bits
rts
@L1: lda #$00 ; Return false

View File

@ -5,14 +5,14 @@
;
.export _isspace
.import __ctype
.include "ctype.inc"
_isspace:
cpx #$00 ; Char range ok?
bne @L1 ; Jump if no
tay
lda __ctype,y ; Get character classification
and #$60 ; Mask space bits
and #(CT_SPACE | CT_OTHER_WS) ; Mask space bits
rts
@L1: lda #$00 ; Return false

View File

@ -5,14 +5,14 @@
;
.export _isupper
.import __ctype
.include "ctype.inc"
_isupper:
cpx #$00 ; Char range ok?
bne @L1 ; Jump if no
tay
lda __ctype,y ; Get character classification
and #$02 ; Mask upper char bit
and #CT_UPPER ; Mask upper char bit
rts
@L1: lda #$00 ; Return false

View File

@ -5,14 +5,14 @@
;
.export _isxdigit
.import __ctype
.include "ctype.inc"
_isxdigit:
cpx #$00 ; Char range ok?
bne @L1 ; Jump if no
tay
lda __ctype,y ; Get character classification
and #$08 ; Mask xdigit bit
and #CT_XDIGIT ; Mask xdigit bit
rts
@L1: lda #$00 ; Return false