From 288b0a14d2376a7314fc35124b54b863e68e40f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Grisez?= Date: Tue, 6 Oct 2015 22:25:09 +0200 Subject: [PATCH] Add a header file that provides a set of useful regex string * One regex to match with a generic URI * One regex to match with email addresses --- gtk/regex.h | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 gtk/regex.h diff --git a/gtk/regex.h b/gtk/regex.h new file mode 100644 index 000000000..308320278 --- /dev/null +++ b/gtk/regex.h @@ -0,0 +1,51 @@ +/* +linphone, gtk-glade interface. +Copyright (C) 2015 Belledonne Communications + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +/* + * Regex matching with any URI that respects the RFC 3986 + */ +#define BC_REGEX_URI_PCT_ENCODED "(%[[:xdigit:]]{2})" +#define BC_REGEX_URI_SUB_DELIMS "[!$&'()*+,;=]" +#define BC_REGEX_URI_UNRESERVED "[[:alnum:]\\-._~]" +#define BC_REGEX_URI_PCHAR "(" BC_REGEX_URI_UNRESERVED "|" BC_REGEX_URI_PCT_ENCODED "|" BC_REGEX_URI_SUB_DELIMS "|" "[:@]" ")" +#define BC_REGEX_URI_SCHEME "(" "[[:alpha:]][[:alnum:]+\\-.]*" ")" +#define BC_REGEX_URI_USERINFO "(" "(" BC_REGEX_URI_UNRESERVED "|" BC_REGEX_URI_PCT_ENCODED "|" BC_REGEX_URI_SUB_DELIMS "|" ":" ")*" ")" +#define BC_REGEX_URI_HOST "(" "(" BC_REGEX_URI_UNRESERVED "|" BC_REGEX_URI_PCT_ENCODED "|" BC_REGEX_URI_SUB_DELIMS ")*" ")" +#define BC_REGEX_URI_PORT "(" "[\\d]*" ")" +#define BC_REGEX_URI_AUTHORITY "(" "(" BC_REGEX_URI_USERINFO "@" ")?" BC_REGEX_URI_HOST "(" ":" BC_REGEX_URI_PORT ")?" ")" +#define BC_REGEX_URI_SEGMENT "(" BC_REGEX_URI_PCHAR "*" ")" +#define BC_REGEX_URI_SEGMENT_NZ "(" BC_REGEX_URI_PCHAR "+" ")" +#define BC_REGEX_URI_PATH_ABEMPTY "(" "(" "/" BC_REGEX_URI_SEGMENT ")*" ")" +#define BC_REGEX_URI_PATH_ABSOLUTE "(" "/" "(" BC_REGEX_URI_SEGMENT_NZ "(" "/" BC_REGEX_URI_SEGMENT ")*" ")?" ")" +#define BC_REGEX_URI_PATH_ROOTLESS "(" BC_REGEX_URI_SEGMENT_NZ "(" "/" BC_REGEX_URI_SEGMENT ")*" ")" +#define BC_REGEX_URI_HIER_PART "(" "//" BC_REGEX_URI_AUTHORITY BC_REGEX_URI_PATH_ABEMPTY "|" BC_REGEX_URI_PATH_ABSOLUTE "|" BC_REGEX_URI_PATH_ROOTLESS ")" +#define BC_REGEX_URI_QUERY "(" "(" BC_REGEX_URI_PCHAR "|" "[/?]" ")*" ")" +#define BC_REGEX_URI_FRAGMENT "(" "(" BC_REGEX_URI_PCHAR "|" "[/?]" ")*" ")" +#define BC_REGEX_URI "(" BC_REGEX_URI_SCHEME ":" BC_REGEX_URI_HIER_PART "(" "\\?" BC_REGEX_URI_QUERY ")?" "(" "#" BC_REGEX_URI_FRAGMENT ")?" ")" + + +/* + * Regex matching with email addresses. + */ +#define BC_REGEX_EMAIL_ATEXT "[[:alnum:]!#$%&'*+\\-/=?\\^_`{}|~]" +#define BC_REGEX_EMAIL_DOT_ATOM_TEXT "(" BC_REGEX_EMAIL_ATEXT "+" "(" "." BC_REGEX_EMAIL_ATEXT "+" ")*" ")" +#define BC_REGEX_EMAIL_LOCAL_PART BC_REGEX_EMAIL_DOT_ATOM_TEXT +#define BC_REGEX_EMAIL_DTEXT_NO_OBS "[!-Z\\^-~]" +#define BC_REGEX_EMAIL_DOMAIN "(" BC_REGEX_EMAIL_DOT_ATOM_TEXT "|" "\\[" BC_REGEX_EMAIL_DTEXT_NO_OBS "*" "\\]" ")" +#define BC_REGEX_EMAIL_ADDR_SPEC "(" BC_REGEX_EMAIL_LOCAL_PART "@" BC_REGEX_EMAIL_DOMAIN ")"