Skip to main content

vcard_parser/
constants.rs

1//! Constants for string matching.
2
3#[non_exhaustive]
4pub struct Cardinality;
5
6impl Cardinality {
7    pub const SINGLE: &'static str = "SINGLE";
8    pub const MULTIPLE: &'static str = "MULTIPLE";
9}
10
11#[non_exhaustive]
12pub struct Encoding;
13
14/// Value parameter possible values, see [RFC 6350 5.2](https://datatracker.ietf.org/doc/html/rfc6350#section-5.2)
15impl Encoding {
16    pub const UNESCAPED_BACKSLASH: char = '\\';
17    pub const UNESCAPED_CR: char = '\r';
18    pub const UNESCAPED_COLON: char = ':';
19    pub const UNESCAPED_COMMA: char = ',';
20    pub const UNESCAPED_EQUALS: char = '=';
21    pub const UNESCAPED_LF: char = '\n';
22    pub const UNESCAPED_SEMICOLON: char = ';';
23    pub const UNESCAPED_TAB: char = '\t';
24
25    pub const ESCAPED_BACKSLASH: &'static str = r"\\";
26    pub const ESCAPED_CR: &'static str = r"\\r";
27    pub const ESCAPED_COLON: &'static str = r"\:";
28    pub const ESCAPED_COMMA: &'static str = r"\,";
29    pub const ESCAPED_EQUALS: &'static str = r"\=";
30    pub const ESCAPED_LF: &'static str = r"\\n";
31    pub const ESCAPED_SEMICOLON: &'static str = r"\;";
32    pub const ESCAPED_TAB: &'static str = r"\\t";
33}
34
35#[non_exhaustive]
36pub struct PropertyName;
37
38impl PropertyName {
39    pub const BEGIN: &'static str = "BEGIN";
40    pub const VERSION: &'static str = "VERSION";
41    pub const END: &'static str = "END";
42
43    pub const ADR: &'static str = "ADR";
44    pub const ANNIVERSARY: &'static str = "ANNIVERSARY";
45    pub const BDAY: &'static str = "BDAY";
46    pub const BIRTHPLACE: &'static str = "BIRTHPLACE";
47    pub const CALADRURI: &'static str = "CALADRURI";
48    pub const CALURI: &'static str = "CALURI";
49    pub const CATEGORIES: &'static str = "CATEGORIES";
50    pub const CLIENTPIDMAP: &'static str = "CLIENTPIDMAP";
51    pub const CONTACTURI: &'static str = "CONTACT-URI";
52    pub const DEATHDATE: &'static str = "DEATHDATE";
53    pub const DEATHPLACE: &'static str = "DEATHPLACE";
54    pub const EMAIL: &'static str = "EMAIL";
55    pub const EXPERTISE: &'static str = "EXPERTISE";
56    pub const FBURL: &'static str = "FBURL";
57    pub const FN: &'static str = "FN";
58    pub const GENDER: &'static str = "GENDER";
59    pub const GEO: &'static str = "GEO";
60    pub const HOBBY: &'static str = "HOBBY";
61    pub const IMPP: &'static str = "IMPP";
62    pub const INTEREST: &'static str = "INTEREST";
63    pub const KEY: &'static str = "KEY";
64    pub const KIND: &'static str = "KIND";
65    pub const LANG: &'static str = "LANG";
66    pub const LOGO: &'static str = "LOGO";
67    pub const MEMBER: &'static str = "MEMBER";
68    pub const NICKNAME: &'static str = "NICKNAME";
69    pub const NOTE: &'static str = "NOTE";
70    pub const N: &'static str = "N";
71    pub const ORGDIRECTORY: &'static str = "ORG-DIRECTORY";
72    pub const ORG: &'static str = "ORG";
73    pub const PHOTO: &'static str = "PHOTO";
74    pub const PRODID: &'static str = "PRODID";
75    pub const RELATED: &'static str = "RELATED";
76    pub const REV: &'static str = "REV";
77    pub const ROLE: &'static str = "ROLE";
78    pub const SOUND: &'static str = "SOUND";
79    pub const SOURCE: &'static str = "SOURCE";
80    pub const TEL: &'static str = "TEL";
81    pub const TITLE: &'static str = "TITLE";
82    pub const TZ: &'static str = "TZ";
83    pub const UID: &'static str = "UID";
84    pub const URL: &'static str = "URL";
85    pub const XML: &'static str = "XML";
86}
87
88#[non_exhaustive]
89pub struct ParameterName;
90
91impl ParameterName {
92    pub const ALTID: &'static str = "ALTID";
93    pub const ANY: &'static str = "ANY";
94    pub const CALSCALE: &'static str = "CALSCALE";
95    pub const CC: &'static str = "CC";
96    pub const GEO: &'static str = "GEO";
97    pub const INDEX: &'static str = "INDEX";
98    pub const LABEL: &'static str = "LABEL";
99    pub const LANGUAGE: &'static str = "LANGUAGE";
100    pub const LEVEL: &'static str = "LEVEL";
101    pub const MEDIATYPE: &'static str = "MEDIATYPE";
102    pub const PID: &'static str = "PID";
103    pub const PREF: &'static str = "PREF";
104    pub const SORTAS: &'static str = "SORT-AS";
105    pub const TYPE: &'static str = "TYPE";
106    pub const TZ: &'static str = "TZ";
107    pub const VALUE: &'static str = "VALUE";
108}
109
110#[non_exhaustive]
111pub struct ValueName;
112
113impl ValueName {
114    pub const BOOLEAN: &'static str = "BOOLEAN";
115    pub const CLIENTPIDMAP: &'static str = "CLIENTPIDMAP";
116    pub const DATE: &'static str = "DATE";
117    pub const FLOAT: &'static str = "FLOAT";
118    pub const INTEGER: &'static str = "INTEGER";
119    pub const LANGUAGE_TAG: &'static str = "LANGUAGETAG";
120    pub const LISTCOMPONENT: &'static str = "LISTCOMPONENT";
121    pub const PID: &'static str = "PID";
122    pub const TEXT: &'static str = "TEXT";
123    pub const TEXTLIST: &'static str = "TEXTLIST";
124    pub const TIMESTAMP: &'static str = "TIMESTAMP";
125    pub const URI: &'static str = "URI";
126    pub const UTCOFFSET: &'static str = "UTCOFFSET";
127}
128
129#[non_exhaustive]
130pub struct ValueType;
131
132/// Value parameter possible values, see [RFC 6350 5.2](https://datatracker.ietf.org/doc/html/rfc6350#section-5.2)
133impl ValueType {
134    pub const BOOLEAN: &'static str = "BOOLEAN";
135    pub const DATE_AND_OR_TIME: &'static str = "DATE-AND-OR-TIME";
136    pub const DATE_TIME: &'static str = "DATE-TIME";
137    pub const DATE: &'static str = "DATE";
138    pub const FLOAT: &'static str = "FLOAT";
139    pub const INTEGER: &'static str = "INTEGER";
140    pub const LANGUAGE_TAG: &'static str = "LANGUAGE-TAG";
141    pub const TEXT: &'static str = "TEXT";
142    pub const TIME: &'static str = "TIME";
143    pub const TIMESTAMP: &'static str = "TIMESTAMP";
144    pub const URI: &'static str = "URI";
145    pub const UTC_OFFSET: &'static str = "UTC-OFFSET";
146
147    pub const TYPES: [&'static str; 12] = [
148        ValueType::BOOLEAN,
149        ValueType::DATE_AND_OR_TIME,
150        ValueType::DATE_TIME,
151        ValueType::DATE,
152        ValueType::FLOAT,
153        ValueType::INTEGER,
154        ValueType::LANGUAGE_TAG,
155        ValueType::TEXT,
156        ValueType::TIME,
157        ValueType::TIMESTAMP,
158        ValueType::URI,
159        ValueType::UTC_OFFSET,
160    ];
161}
162
163#[non_exhaustive]
164pub struct PropertyExpertiseValues;
165
166impl PropertyExpertiseValues {
167    pub const BEGINNER: &'static str = "BEGINNER";
168    pub const AVERAGE: &'static str = "AVERAGE";
169    pub const EXPERT: &'static str = "EXPERT";
170    pub const LOW: &'static str = "LOW";
171    pub const MEDIUM: &'static str = "MEDIUM";
172    pub const HIGH: &'static str = "HIGH";
173
174    pub const TYPES: [&'static str; 6] = [
175        PropertyExpertiseValues::BEGINNER,
176        PropertyExpertiseValues::AVERAGE,
177        PropertyExpertiseValues::EXPERT,
178        PropertyExpertiseValues::LOW,
179        PropertyExpertiseValues::MEDIUM,
180        PropertyExpertiseValues::HIGH,
181    ];
182}
183
184#[non_exhaustive]
185pub struct PropertyGenderValues;
186
187impl PropertyGenderValues {
188    pub const M: &'static str = "M";
189    pub const F: &'static str = "F";
190    pub const N: &'static str = "N";
191    pub const O: &'static str = "O";
192    pub const U: &'static str = "U";
193
194    pub const TYPES: [&'static str; 5] = [
195        PropertyGenderValues::M,
196        PropertyGenderValues::F,
197        PropertyGenderValues::N,
198        PropertyGenderValues::O,
199        PropertyGenderValues::U,
200    ];
201}
202
203#[non_exhaustive]
204pub struct PropertyHobbyValues;
205
206impl PropertyHobbyValues {
207    pub const LOW: &'static str = "LOW";
208    pub const MEDIUM: &'static str = "MEDIUM";
209    pub const HIGH: &'static str = "HIGH";
210
211    pub const TYPES: [&'static str; 3] = [
212        PropertyHobbyValues::LOW,
213        PropertyHobbyValues::MEDIUM,
214        PropertyHobbyValues::HIGH,
215    ];
216}
217
218#[non_exhaustive]
219pub struct PropertyInterestValues;
220
221impl PropertyInterestValues {
222    pub const LOW: &'static str = "LOW";
223    pub const MEDIUM: &'static str = "MEDIUM";
224    pub const HIGH: &'static str = "HIGH";
225
226    pub const TYPES: [&'static str; 3] = [
227        PropertyInterestValues::LOW,
228        PropertyInterestValues::MEDIUM,
229        PropertyInterestValues::HIGH,
230    ];
231}
232
233#[non_exhaustive]
234pub struct PropertyKindValues;
235
236impl PropertyKindValues {
237    pub const INDIVIDUAL: &'static str = "INDIVIDUAL";
238    pub const GROUP: &'static str = "GROUP";
239    pub const ORG: &'static str = "ORG";
240    pub const LOCATION: &'static str = "LOCATION";
241
242    pub const TYPES: [&'static str; 4] = [
243        PropertyKindValues::INDIVIDUAL,
244        PropertyKindValues::GROUP,
245        PropertyKindValues::ORG,
246        PropertyKindValues::LOCATION,
247    ];
248}
249
250#[non_exhaustive]
251pub struct TestData;
252
253impl TestData {
254    pub const VCARD_ERROR_VERSION_INCORRECT: &'static str = "BEGIN:VCARD\nVERSION:3.0\nFN:John Doe\nEND:VCARD\n";
255    pub const VCARD_ERROR_VERSION_MISSING: &'static str = "BEGIN:VCARD\nFN:John Doe\nEND:VCARD\n";
256    pub const VCARD_ERROR_BEGIN_MISSING: &'static str = "VERSION:4.0\nFN:John Doe\nEND:VCARD\n";
257    pub const VCARD_ERROR_END_MISSING: &'static str = "BEGIN:VCARD\nVERSION:4.0\nFN:John Doe\n";
258    pub const VCARD_ERROR_FULLNAME_MISSING: &'static str = "BEGIN:VCARD\nVERSION:4.0\nEND:VCARD\n";
259    pub const VCARD_MATCH_MINIMAL: (&'static str, &'static str) = ("BEGIN:VCARD\nVERSION:4.0\nFN:John Doe\nEND:VCARD\n", "BEGIN:VCARD\nVERSION:4.0\nFN:John Doe\nEND:VCARD\n");
260    pub const VCARD_MATCH_CONCAT: (&'static str, &'static str) = ("BEGIN:VCARD\nVERSION:4.0\nFN:John Doe\nN:Doe;\n John\n\t;Jr.;;\nEND:VCARD\n", "BEGIN:VCARD\nVERSION:4.0\nFN:John Doe\nN:Doe;John;Jr.;;\nEND:VCARD\n");
261    pub const VCARD_MATCH_XNAME: (&'static str, &'static str) = ("BEGIN:VCARD\nVERSION:4.0\nFN:John Doe\nitem1.X-ABADR;X-SERVICE=TEST:us\nEND:VCARD\n", "BEGIN:VCARD\nVERSION:4.0\nFN:John Doe\nitem1.X-ABADR;X-SERVICE=TEST:us\nEND:VCARD\n");
262    pub const VCARD_MATCH_COMPOUND: (&'static str, &'static str) = ("BEGIN:VCARD\nVERSION:4.0\nFN:John Doe\nEMAIL;TYPE=\"INTERNET,HOME\":user@example.com\nEND:VCARD\n", "BEGIN:VCARD\nVERSION:4.0\nFN:John Doe\nEMAIL;TYPE=\"INTERNET,HOME\":user@example.com\nEND:VCARD\n");
263}
264
265#[non_exhaustive]
266pub struct TestDataPropertyValues;
267
268impl TestDataPropertyValues {
269    pub const ADR: &'static str = r";;123 Main Street;Any Town;CA;91921-1234;U.S.A.";
270    pub const ANNIVERSARY: &'static str = r"19960415";
271    pub const BDAY: &'static str = r"19531015T231000Z";
272    pub const BIRTHPLACE: &'static str = r"geo:46.769307,-71.283079";
273    pub const CALADRURI: &'static str = r"mailto:janedoe@example.com";
274    pub const CALURI: &'static str = r"ftp://ftp.example.com/calA.ics";
275    pub const CATEGORIES: &'static str = r"INTERNET,IETF,INDUSTRY,INFORMATION TECHNOLOGY";
276    pub const CLIENTPIDMAP: &'static str = r"1;urn:uuid:3df403f4-5924-4bb7-b077-3c711d9eb34b";
277    pub const CONTACTURI: &'static str = r"https://contact.example.com";
278    pub const DEATHDATE: &'static str = r"circa 1800";
279    pub const DEATHPLACE: &'static str = r"Aboard the Titanic\, near Newfoundland";
280    pub const EMAIL: &'static str = r"jqpublic@xyz.example.com";
281    pub const EXPERTISE: &'static str = r"chemistry";
282    pub const FBURL: &'static str = r"ftp://example.com/busy/project-a.ifb";
283    pub const FN: &'static str = r"Mr. John Q. Public\, Esq.";
284    pub const GENDER: &'static str = r"M;Fellow";
285    pub const GEO: &'static str = r"geo:37.386013,-122.082932";
286    pub const HOBBY: &'static str = r"reading";
287    pub const IMPP: &'static str = r"xmpp:alice@example.com";
288    pub const INTEREST: &'static str = r"rock 'n' roll music";
289    pub const KEY: &'static str = r"ftp://example.com/keys/jdoe";
290    pub const KIND: &'static str = r"individual";
291    pub const LANG: &'static str = r"en";
292    pub const LOGO: &'static str = r"https://www.example.com/pub/logos/abccorp.jpg";
293    pub const MEMBER: &'static str = r"mailto:subscriber1@example.com";
294    pub const NICKNAME: &'static str = r"Jim,Jimmie";
295    pub const NOTE: &'static str = r"This fax number is operational 0800 to 1715\\nEST\, Mon-Fri.";
296    pub const N: &'static str = r"N:Public;John;Quinlan;Mr.;Esq.";
297    pub const ORGDIRECTORY: &'static str = r"ldap://ldap.tech.example/o=Example%20Tech,ou=Engineering";
298    pub const ORG: &'static str = r"ABC\, Inc.;North American Division;Marketing";
299    pub const PHOTO: &'static str = r"data:image/jpeg;base64,MIICajCCAdOgAwIBAgICBEUwDQYJKoZIhv";
300    pub const PRODID: &'static str = r"-//ONLINE DIRECTORY//NONSGML Version 1//EN";
301    pub const RELATED: &'static str = r"contact:https://example.com/directory/jdoe.vcf";
302    pub const REV: &'static str = r"19951031T222710Z";
303    pub const ROLE: &'static str = r"Project Leader";
304    pub const SOUND: &'static str = r"CID:JOHNQPUBLIC.part8.19960229T080000.xyzMail@example.com";
305    pub const SOURCE: &'static str = r"ldap://ldap.example.com/cn=Babs%20Jensen,%20o=Babsco,%20c=US";
306    pub const TEL: &'static str = r"tel:+1-555-555-5555;ext=5555";
307    pub const TITLE: &'static str = r"Research Scientist";
308    pub const TZ: &'static str = r"Raleigh/North America";
309    pub const UID: &'static str = r"urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6";
310    pub const URL: &'static str = r"https://example.org/restaurant.french/~chezchic.html";
311    pub const XML: &'static str = r#"<?xml version=\"1.0\" encoding=\"UTF-8\"?><vcards xmlns=\"urn:ietf:params:xml:ns:vcard-4.0\"><vcard></vcard></vcards>"#;
312}
313
314#[non_exhaustive]
315pub struct VcardParseError;
316
317impl VcardParseError {
318    pub const DELIMITER_COLON: &'static str = "DELIMITER_COLON";
319    pub const DELIMITER_COMMA: &'static str = "DELIMITER_COMMA";
320    pub const DELIMITER_CONCAT: &'static str = "DELIMITER_CONCAT";
321    pub const DELIMITER_EQUALS: &'static str = "DELIMITER_EQUALS";
322    pub const DELIMITER_SEMI_COLON: &'static str = "DELIMITER_SEMI_COLON";
323    pub const PARAMETER: &'static str = "PARAMETER";
324    pub const PARAMETER_TYPE: &'static str = "PARAMETER_TYPE";
325    pub const PARAMETER_VALUE: &'static str = "PARAMETER_VALUE";
326    pub const PARAMETER_XNAME: &'static str = "PARAMETER_XNAME";
327    pub const PROPERTY: &'static str = "PROPERTY";
328    pub const PROPERTY_BEGIN: &'static str = "PROPERTY_BEGIN";
329    pub const PROPERTY_BEGIN_MISSING: &'static str = "PROPERTY_BEGIN_MISSING";
330    pub const PROPERTY_END: &'static str = "PROPERTY_END";
331    pub const PROPERTY_END_MISSING: &'static str = "PROPERTY_END_MISSING";
332    pub const PROPERTY_GROUP: &'static str = "PROPERTY_GROUP";
333    pub const PROPERTY_IANA_TOKEN: &'static str = "PROPERTY_IANA_TOKEN";
334    pub const PROPERTY_NAME: &'static str = "PROPERTY_NAME";
335    pub const PROPERTY_VALUE: &'static str = "PROPERTY_VALUE";
336    pub const PROPERTY_VERSION: &'static str = "PROPERTY_VERSION";
337    pub const PROPERTY_VERSION_MISSING: &'static str = "PROPERTY_VERSION_MISSING";
338    pub const PROPERTY_XNAME: &'static str = "PROPERTY_XNAME";
339    pub const VALUE: &'static str = "VALUE";
340    pub const VALUE_FOLDED: &'static str = "VALUE_FOLDED";
341    pub const VALUE_QSAFE: &'static str = "VALUE_QSAFE";
342    pub const VALUE_SAFE: &'static str = "VALUE_SAFE";
343    pub const VCARD: &'static str = "VCARD";
344    pub const VCARDS: &'static str = "VCARDS";
345}