PPCharSetPredicate.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Mon, 03 Nov 2014 12:46:42 +0000
changeset 410 779556be95f8
parent 54 3e4cde74f2ea
child 427 a7f5e6de19d2
permissions -rw-r--r--
Portability fixes in PPPredicateTest>>charactersDo: / parsedCharacterSet: * It is my understanding that charactersDo: should iterate over all signle byte characters. If so, the method suffer from off-by-one error, it should generate characters with code points 0..255. 256 is actually a two-byte character. Method changed accordingly. * Use Character>>asString instead of `String>>with:` which is safer w.r.t. multi-byte characters. Under Smalltalk/X, String may contain only signle byte characters.

"{ Package: 'stx:goodies/petitparser' }"

Object subclass:#PPCharSetPredicate
	instanceVariableNames:'block classification'
	classVariableNames:''
	poolDictionaries:''
	category:'PetitParser-Tools'
!


!PPCharSetPredicate class methodsFor:'instance creation'!

on: aBlock
	^ self basicNew initializeOn: aBlock
! !

!PPCharSetPredicate methodsFor:'evaluating'!

value: aCharacter
	| index |
	index := aCharacter asInteger.
	index == 0
		ifTrue: [ ^ block value: aCharacter ].
	index > 255
		ifTrue: [ ^ block value: aCharacter ].
	^ classification at: index
! !

!PPCharSetPredicate methodsFor:'initialization'!

initializeOn: aBlock
	block := aBlock.
	classification := Array new: 255.
	1 to: classification size do: [ :index |
		classification at: index put: (block
			value: (Character value: index)) ]
! !

!PPCharSetPredicate class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/goodies/petitparser/PPCharSetPredicate.st,v 1.3 2012-05-04 22:09:50 vrany Exp $'
!

version_CVS
    ^ '$Header: /cvs/stx/stx/goodies/petitparser/PPCharSetPredicate.st,v 1.3 2012-05-04 22:09:50 vrany Exp $'
!

version_SVN
    ^ '§Id: PPCharSetPredicate.st 4 2010-12-18 17:02:23Z kursjan §'
! !