Merge pull request #19321 from colemanw/profileGetFieldsFix
[civicrm-core.git] / CRM / Utils / String.php
index 654b74ff0ebcb41cbd4c28162935265021dbebe0..8e761a5be8231f11393b9cc4accd14d4c817571c 100644 (file)
@@ -221,6 +221,31 @@ class CRM_Utils_String {
     }
   }
 
+  /**
+   * Encode string using URL-safe Base64.
+   *
+   * @param string $v
+   *
+   * @return string
+   * @see https://tools.ietf.org/html/rfc4648#section-5
+   */
+  public static function base64UrlEncode($v) {
+    return rtrim(str_replace(['+', '/'], ['-', '_'], base64_encode($v)), '=');
+  }
+
+  /**
+   * Decode string using URL-safe Base64.
+   *
+   * @param string $v
+   *
+   * @return false|string
+   * @see https://tools.ietf.org/html/rfc4648#section-5
+   */
+  public static function base64UrlDecode($v) {
+    // PHP base64_decode() is already forgiving about padding ("=").
+    return base64_decode(str_replace(['-', '_'], ['+', '/'], $v));
+  }
+
   /**
    * Determine the string replacements for redaction.
    * on the basis of the regular expressions
@@ -941,10 +966,10 @@ class CRM_Utils_String {
   public static function pluralize($str) {
     $lastLetter = substr($str, -1);
     $lastTwo = substr($str, -2);
-    if ($lastLetter == 's' || $lastTwo == 'ch') {
+    if ($lastLetter == 's' || $lastLetter == 'x' || $lastTwo == 'ch') {
       return $str . 'es';
     }
-    if ($lastLetter == 'y' && $lastTwo != 'ey') {
+    if ($lastLetter == 'y' && !in_array($lastTwo, ['ay', 'ey', 'iy', 'oy', 'uy'])) {
       return substr($str, 0, -1) . 'ies';
     }
     return $str . 's';