Lazarus
Free Pascal => General => Topic started by: Zvoni on October 24, 2020, 11:21:00 am
Title:
[solved] How to check if an Integer is a control-character?
Post by:
Zvoni
on
October 24, 2020, 11:21:00 am
Hi Folks,
still translating c-code.
How do i check if a Integer is a control-character?
Code: C
[Select]
[+]
[-]
int
MyFunction
(
int
c
)
{
return
c
==
' '
||
c
==
'
\f
'
||
c
==
'
\n
'
||
c
==
'
\r
'
||
c
==
'
\t
'
||
c
==
'
\v
'
;
}
Code: Pascal
[Select]
[+]
[-]
Function
MyFunction
(
c
:
Integer
)
:
Boolean
Begin
Result
:
=
(
c
=
Ord
(
' '
)
)
Or
//???????
End
;
For the life of me i can't find anyting for this.
And yes, i'm aware that i'm checking if c is a whitespace-character
And, no. I'm using {H+} so IsWhiteSpace-Function is not option.
EDIT: After reading up on it: Or is it enough to check if #32 and everything <= #13 ?
Title:
Re: How to check if an Integer is a control-character?
Post by:
Bart
on
October 24, 2020, 11:35:51 am
Basically you want to detect CarriageReturn, LineFeed, FormFeed, Space, Tab and VerticalTab.
Integer values:
CarriageReturn = 13
LineFeed = 10
FormFeed = 12
VertcalTab = 11
Tab = 9
Space = 32
Code: Pascal
[Select]
[+]
[-]
function
MyFunction
(
C
:
Integer
)
:
Boolean
;
begin
Result
:
=
(
C
in
[
9
,
11
,
12
,
13
,
32
]
)
;
end
;
Or
Code: Pascal
[Select]
[+]
[-]
function
MyFunction
(
C
:
Char
)
:
Boolean
;
begin
Result
:
=
(
C
in
[
#9
,
#11
,
#12
,
#13
,
#32
]
)
;
end
;
Bart
Title:
Re: How to check if an Integer is a control-character?
Post by:
Bart
on
October 24, 2020, 12:04:49 pm
See also https://en.wikipedia.org/wiki/Escape_sequences_in_C (https://en.wikipedia.org/wiki/Escape_sequences_in_C)
Bart
Title:
Re: How to check if an Integer is a control-character?
Post by:
Zvoni
on
October 24, 2020, 12:17:43 pm
Thx Bart, so i was close with my second guess
TinyPortal
© 2005-2018