Skip to content

ispunct differs from the function with the same name in C, could be worth a note #56680

Closed
@inkydragon

Description

@inkydragon

Not sure if this is a bug.
This seems intentional, but the ispunct in julia is inconsistent with the behavior of the C function of the same name, which is confusing.

Perhaps a warning could be added to clarify the inconsistency with C.

https://en.cppreference.com/w/cpp/string/byte/ispunct

julia> c = '+'
'+': ASCII/Unicode U+002B (category Sm: Symbol, math)

julia> ispunct(c)
false

julia> ( @ccall ispunct(c::Cchar)::Cint ) != 0
true

julia> c = '-'
'-': ASCII/Unicode U+002D (category Pd: Punctuation, dash)

julia> (ispunct(c), ( @ccall ispunct(c::Cchar)::Cint )!= 0)
(true, true)
  ispunct(c::AbstractChar) -> Bool

  Tests whether a character belongs to the Unicode general category Punctuation, i.e. a character whose category code
  begins with 'P'.

And more chars:

julia> for c in raw"""!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~"""
           ispunct(c) || println(c)
       end
$
+
<
=
>
^
`
|
~

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsThis change adds or pertains to documentationunicodeRelated to unicode characters and encodings

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions