CPE_learningsite
This repository has no backups
This repository's network speed is throttled to 100KB/sec
Upgrade your account to fix these warnings, or use backups.vc for automated backups
feature/Change_Message_notification
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using Newtonsoft.Json.Serialization; namespace CPE.App.Web.Elucidat { public static class StringExtensions { private static readonly Dictionary<string, string> ToBeEncoded = new Dictionary<string, string>() { { "%", "%25" }, { "!", "%21" }, { "#", "%23" }, { " ", "%20" }, { "$", "%24" }, { "&", "%26" }, { "'", "%27" }, { "(", "%28" }, { ")", "%29" }, { "*", "%2A" }, { "+", "%2B" }, { ",", "%2C" }, { "/", "%2F" }, { ":", "%3A" }, { ";", "%3B" }, { "=", "%3D" }, { "?", "%3F" }, { "@", "%40" }, { "[", "%5B" }, { "]", "%5D" } }; private static readonly Regex ReplaceRegex = new Regex(@"[%!# $&'()*+,/:;=?@\[\]]"); /// <summary> /// .NET URL encoding functions (e.g. WebUtility.UrlEncode) do not precisely match the action of php rawurlencode(), /// which is used by the Elucidat API for signature checking. Therefore we use this custom function instead when URL encoding /// any data to be sent to the API or used in signature generation. /// </summary> /// <param name="s">The string to be encoded</param> /// <returns>The encoded string</returns> public static string RawUrlEncode(this string s) { return ReplaceRegex.Replace(s, match => ToBeEncoded[match.Value]); } /// <summary> /// Transform a .NET style property name (e.g. ProjectCode) into a PHP-style property name (e.g. project_code) /// </summary> /// <param name="propertyName"></param> /// <returns></returns> public static string TransformPropertyName(this string propertyName) { return String.Join("_", Regex.Split(propertyName, "(?=[A-Z])").Where(x => !String.IsNullOrWhiteSpace(x))).ToLower(); } } } |
Commits for CPE_learningsiteCPE/CPE.App/CPE.App.Web/Elucidat/StringExtensions.cs
Revision | Author | Commited | Message |
---|---|---|---|
4cd176 ... | v.shishlov | Fri 27 Aug, 2021 14:33:17 +0000 | initial commit |