Module: Vcard::Bnf

Defined in:
lib/vcard/bnf.rb

Overview

Contains regular expressions for the EBNF of RFC 2425.

Constant Summary collapse

NAME =

1*(ALPHA / DIGIT / “-”) Note: “_” allowed because produced by Notes (X-LOTUS-CHILD_UID:) Note: “/” allowed because produced by KAddressBook (X-messaging/xmpp-All:) Note: “ ” allowed because produced by highrisehq.com (X-GOOGLE TALK:)

/[\w\/-][ \w\/-]*/
QSTR =

<“> <Any character except CTLs, DQUOTE> <”>

/"([^"]*)"/
PTEXT =

*<Any character except CTLs, DQUOTE, “;”, “:”, “,”>

/([^";:,]+)/
PVALUE =

param-value = ptext / quoted-string

/(?:#{QSTR}|#{PTEXT})/
PARAM =

param = name “=” param-value *(“,” param-value) Note: v2.1 allows a type or encoding param-value to appear without the type= or the encoding=. This is hideous, but we try and support it, if there is no “=”, then $2 will be “”, and we will treat it as a v2.1 param.

/;(#{NAME})(=?)((?:#{PVALUE})?(?:,#{PVALUE})*)/
LINE =

V3.0: contentline = [group “.”] name *(“;” param) “:” value V2.1: contentline = *( group “.” ) name *(“;” param) “:” value We accept the V2.1 syntax for backwards compatibility.

/\A((?:#{NAME}\.)*)?(#{NAME})((?:#{PARAM})*):(.*)\z/
DATE_PARTIAL =

date = date-fullyear [“-”] date-month [“-”] date-mday date-fullyear = 4 DIGIT date-month = 2 DIGIT date-mday = 2 DIGIT

/(\d\d\d\d)-?(\d\d)-?(\d\d)/
DATE =
/\A\s*#{DATE_PARTIAL}\s*\z/
TIME_PARTIAL =

time = time-hour [“:”] time-minute [“:”] time-second [time-secfrac] [time-zone] time-hour = 2 DIGIT time-minute = 2 DIGIT time-second = 2 DIGIT time-secfrac = “,” 1*DIGIT time-zone = “Z” / time-numzone time-numzone = sign time-hour [“:”] time-minute

/(\d\d):?(\d\d):?(\d\d)(\.\d+)?(Z|[-+]\d\d:?\d\d)?/
TIME =
/\A\s*#{TIME_PARTIAL}\s*\z/
DATE_TIME =

date-time = date “T” time

/\A\s*#{DATE_PARTIAL}T#{TIME_PARTIAL}\s*\z/
INTEGER =

integer = ([“+”] / “-”) 1*DIGIT

/\A\s*[-+]?\d+\s*\z/
QSAFECHAR =

JRuby in 1.8 mode doesn’t respect the file encoding. See github.com/jruby/jruby/issues/1191

Regexp.new("[ \t\x21\x23-\x7e\x80-\xff]")
ALL_QSAFECHARS =
/\A#{QSAFECHAR}*\z/
SAFECHAR =

SAFE-CHAR = WSP / %x21 / %x23-2B / %x2D-39 / %x3C-7E / NON-US-ASCII

; Any character except CTLs, DQUOTE, ";", ":", ","

escape character classes then create new Regexp

Regexp.new(Regexp.escape("[ \t\x21\x23-\x2b\x2d-\x39\x3c-\x7e\x80-\xff]"))
ALL_SAFECHARS =
/\A#{SAFECHAR}*\z/
UNTERMINATED_QUOTED_PRINTABLE =

A quoted-printable encoded string with a trailing ‘=’, indicating that it’s not terminated

/ENCODING=QUOTED-PRINTABLE:.*=$/