9

I haven't been able to find documentation of which characters compound the punctuation set "%p" in Lua.

Deduplicator
  • 41,806
  • 6
  • 61
  • 104
user3325563
  • 167
  • 1
  • 10

3 Answers3

10

The answer is locale dependent, it is a direct interface to the C function.
Actually, if there is a C standard function which does something similar to the Lua function, it is near-certain that the Lua function just wraps the C function, warts and all, even without looking at the specific case.
(This is part of the reason file:read() still has trouble reading text with embedded zeroes in 5.2, maybe even will have in 5.3)

While Amaden gave a good answer for the "C" locale, and ColonelThirtyTwo gave the right way to check for the current locale, the C standard only says:

ispunct(): The ispunct function tests for any printing character that is one of a locale-specific set of punctuation characters for which neither isspace nor isalnum is true. In the "C" locale, ispunct returns true for every printing character for which neither isspace nor isalnum is true.

Deduplicator
  • 41,806
  • 6
  • 61
  • 104
8

%p is matched by the C function ispunct (C source v 5.2), which matches the following:

041 ‘‘!’’     042 ‘‘ ’’       043 ‘‘#’’       044 ‘‘$’’       045 ‘‘%’’ 
046 ‘‘&’’     047 ‘‘’’’       050 ‘‘(’’       051 ‘‘)’’       052 ‘‘*’’ 
053 ‘‘+’’     054 ‘‘,’’       055 ‘‘-’’       056 ‘‘.’’       057 ‘‘/’’ 
072 ‘‘:’’     073 ‘‘;’’       074 ‘‘<’’       075 ‘‘=’’       076 ‘‘>’’ 
077 ‘‘?’’     100 ‘‘@’’       133 ‘‘[’’       134 ‘‘\’’       135 ‘‘]’’ 
136 ‘‘^’’     137 ‘‘_’’       140 ‘‘‘’’       173 ‘‘{’’       174 ‘‘|’’ 
175 ‘‘}’’     176 ‘‘~’’

(From man ispunct)

Etan Reisner
  • 68,917
  • 7
  • 78
  • 118
Amadan
  • 169,219
  • 18
  • 195
  • 256
8

A small script to find them:

for i=0,255 do
    if string.match(string.char(i), "%p") then
        io.write(string.char(i))
    end
end
io.write("\n")

-- $ luajit test.lua
-- !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
Colonel Thirty Two
  • 18,351
  • 7
  • 32
  • 69