[evolution-data-server/sqlite-refactor: 9/13] EPhoneNumber: Add comparisons for not null terminated strings.



commit 339e0fb13dd853388b7b75a4a3f950dd34ad7145
Author: Tristan Van Berkom <tristanvb openismus com>
Date:   Sat Nov 23 15:03:50 2013 +0900

    EPhoneNumber: Add comparisons for not null terminated strings.

 .../libebook-contacts/e-phone-number-private.cpp   |   24 ++++++++
 .../libebook-contacts/e-phone-number-private.h     |    6 ++
 addressbook/libebook-contacts/e-phone-number.c     |   59 ++++++++++++++++---
 addressbook/libebook-contacts/e-phone-number.h     |    7 ++
 4 files changed, 86 insertions(+), 10 deletions(-)
---
diff --git a/addressbook/libebook-contacts/e-phone-number-private.cpp 
b/addressbook/libebook-contacts/e-phone-number-private.cpp
index f0acc2b..c0dc6d5 100644
--- a/addressbook/libebook-contacts/e-phone-number-private.cpp
+++ b/addressbook/libebook-contacts/e-phone-number-private.cpp
@@ -339,6 +339,30 @@ _e_phone_number_cxx_compare_strings (const gchar *first_number,
        return _e_phone_number_cxx_compare (pn1, pn2);
 }
 
+EPhoneNumberMatch
+_e_phone_number_cxx_compare_bytes (const gchar *first_number,
+                                  gsize        first_bytes,
+                                  const gchar *second_number,
+                                  gsize        second_bytes,
+                                  const gchar *region_code,
+                                  GError     **error)
+{
+       g_return_val_if_fail (NULL != first_number, E_PHONE_NUMBER_MATCH_NONE);
+       g_return_val_if_fail (NULL != second_number, E_PHONE_NUMBER_MATCH_NONE);
+
+       const std::string phone_number_a (first_number, first_bytes);
+       const std::string phone_number_b (second_number, second_bytes);
+       const std::string region = _e_phone_number_cxx_make_region_code (region_code);
+       PhoneNumber pn1, pn2;
+
+       if (!_e_phone_number_cxx_parse (phone_number_a, region, &pn1, error))
+               return E_PHONE_NUMBER_MATCH_NONE;
+       if (!_e_phone_number_cxx_parse (phone_number_b, region, &pn2, error))
+               return E_PHONE_NUMBER_MATCH_NONE;
+
+       return _e_phone_number_cxx_compare (pn1, pn2);
+}
+
 EPhoneNumber *
 _e_phone_number_cxx_copy (const EPhoneNumber *phone_number)
 {
diff --git a/addressbook/libebook-contacts/e-phone-number-private.h 
b/addressbook/libebook-contacts/e-phone-number-private.h
index 0f80491..2b7c1de 100644
--- a/addressbook/libebook-contacts/e-phone-number-private.h
+++ b/addressbook/libebook-contacts/e-phone-number-private.h
@@ -76,6 +76,12 @@ E_PHONE_NUMBER_LOCAL EPhoneNumberMatch       _e_phone_number_cxx_compare_strings     (cons
                                                                                 const gchar *second_number,
                                                                                 const gchar *region_code,
                                                                                 GError **error);
+E_PHONE_NUMBER_LOCAL EPhoneNumberMatch _e_phone_number_cxx_compare_bytes       (const gchar *first_number,
+                                                                                gsize first_bytes,
+                                                                                const gchar *second_number,
+                                                                                gsize second_bytes,
+                                                                                const gchar *region_code,
+                                                                                GError **error);
 E_PHONE_NUMBER_LOCAL EPhoneNumber *    _e_phone_number_cxx_copy                (const EPhoneNumber 
*phone_number);
 E_PHONE_NUMBER_LOCAL void              _e_phone_number_cxx_free                (EPhoneNumber *phone_number);
 
diff --git a/addressbook/libebook-contacts/e-phone-number.c b/addressbook/libebook-contacts/e-phone-number.c
index 55ef37c..758f327 100644
--- a/addressbook/libebook-contacts/e-phone-number.c
+++ b/addressbook/libebook-contacts/e-phone-number.c
@@ -342,28 +342,37 @@ e_phone_number_compare_strings (const gchar *first_number,
 }
 
 /**
- * e_phone_number_compare_strings_with_region:
+ * e_phone_number_compare_bytes_with_region:
  * @first_number: the first EPhoneNumber to compare
+ * @first_bytes: length of the @first_number string
  * @second_number: the second EPhoneNumber to compare
+ * @second_bytes: length of the @second_number string
  * @region_code: (allow-none): a two-letter country code, or %NULL
- * @error: (out): a #GError to set an error, if any
+ * @error: (allow-none) (out): a #GError to set an error, if any
  *
- * Compares two phone numbers within the context of @region_code.
+ * Compares two phone numbers, like e_phone_number_compare_strings_with_region()
+ * except that the @first_number and @second_number are not %NULL terminated.
  *
  * Returns: The quality of matching for the two phone numbers.
  *
- * Since: 3.8
+ * Since: 3.12
  **/
 EPhoneNumberMatch
-e_phone_number_compare_strings_with_region (const gchar *first_number,
-                                            const gchar *second_number,
-                                            const gchar *region_code,
-                                            GError **error)
+e_phone_number_compare_bytes_with_region (const gchar *first_number,
+                                         gsize first_bytes,
+                                         const gchar *second_number,
+                                         gsize second_bytes,
+                                         const gchar *region_code,
+                                         GError **error)
 {
 #ifdef ENABLE_PHONENUMBER
 
-       return _e_phone_number_cxx_compare_strings (
-               first_number, second_number, region_code, error);
+       return _e_phone_number_cxx_compare_bytes (first_number,
+                                                 first_bytes,
+                                                 second_number,
+                                                 second_bytes,
+                                                 region_code,
+                                                 error);
 
 #else /* ENABLE_PHONENUMBER */
 
@@ -374,6 +383,36 @@ e_phone_number_compare_strings_with_region (const gchar *first_number,
 }
 
 /**
+ * e_phone_number_compare_strings_with_region:
+ * @first_number: the first EPhoneNumber to compare
+ * @second_number: the second EPhoneNumber to compare
+ * @region_code: (allow-none): a two-letter country code, or %NULL
+ * @error: (out): a #GError to set an error, if any
+ *
+ * Compares two phone numbers within the context of @region_code.
+ *
+ * Returns: The quality of matching for the two phone numbers.
+ *
+ * Since: 3.8
+ **/
+EPhoneNumberMatch
+e_phone_number_compare_strings_with_region (const gchar *first_number,
+                                            const gchar *second_number,
+                                            const gchar *region_code,
+                                            GError **error)
+{
+       g_return_val_if_fail (first_number && first_number[0], E_PHONE_NUMBER_MATCH_NONE);
+       g_return_val_if_fail (second_number && second_number[0], E_PHONE_NUMBER_MATCH_NONE);
+
+       return e_phone_number_compare_bytes_with_region (first_number,
+                                                        strlen (first_number),
+                                                        second_number,
+                                                        strlen (second_number),
+                                                        region_code,
+                                                        error);
+}
+
+/**
  * e_phone_number_copy:
  * @phone_number: the EPhoneNumber to copy
  *
diff --git a/addressbook/libebook-contacts/e-phone-number.h b/addressbook/libebook-contacts/e-phone-number.h
index 1870f66..51f560c 100644
--- a/addressbook/libebook-contacts/e-phone-number.h
+++ b/addressbook/libebook-contacts/e-phone-number.h
@@ -234,6 +234,13 @@ EPhoneNumberMatch  e_phone_number_compare_strings_with_region
                                                         const gchar *second_number,
                                                         const gchar *region_code,
                                                         GError **error);
+EPhoneNumberMatch       e_phone_number_compare_bytes_with_region
+                                                       (const gchar *first_number,
+                                                        gsize first_bytes,
+                                                        const gchar *second_number,
+                                                        gsize second_bytes,
+                                                        const gchar *region_code,
+                                                        GError **error);
 
 EPhoneNumber *         e_phone_number_copy             (const EPhoneNumber *phone_number);
 void                   e_phone_number_free             (EPhoneNumber *phone_number);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]