packages feed

aeson-jsonpath-0.4.2.0: src/Data/Aeson/JSONPath/Parser/Common.hs

module Data.Aeson.JSONPath.Parser.Common where

import qualified Text.ParserCombinators.Parsec as P
import           Text.ParserCombinators.Parsec ((<?>))
import           Data.Char (ord)

import Prelude

-- https://www.rfc-editor.org/rfc/rfc9535#name-syntax
pSpaces :: P.Parser [Char]
pSpaces = P.many (P.oneOf " \n\r\t") <?> "spaces"

pUnicodeChar :: P.Parser Char
pUnicodeChar = P.satisfy inRange <?> "unicode char"
  where
    inRange c = let code = ord c in
      (code >= 0x80 && code <= 0xD7FF) ||
      (code >= 0xE000 && code <= 0x10FFFF)