| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System; |
| | 5 | | using System.Collections.Generic; |
| | 6 | | using System.Text; |
| | 7 | |
|
| | 8 | | namespace Azure.Storage.Shared |
| | 9 | | { |
| | 10 | | internal static class StorageExtensions |
| | 11 | | { |
| | 12 | | public static string EscapePath(this string path) |
| | 13 | | { |
| 0 | 14 | | if (path == null) |
| | 15 | | { |
| 0 | 16 | | return null; |
| | 17 | | } |
| | 18 | |
|
| 0 | 19 | | path = path.Trim('/'); |
| 0 | 20 | | string[] split = path.Split('/'); |
| | 21 | |
|
| 0 | 22 | | for (int i = 0; i < split.Length; i++) |
| | 23 | | { |
| 0 | 24 | | split[i] = Uri.EscapeDataString(split[i]); |
| | 25 | | } |
| | 26 | |
|
| 0 | 27 | | return string.Join("/", split); |
| | 28 | | } |
| | 29 | |
|
| | 30 | | public static string UnescapePath(this string path) |
| | 31 | | { |
| 748 | 32 | | if (path == null) |
| | 33 | | { |
| 0 | 34 | | return null; |
| | 35 | | } |
| | 36 | |
|
| 748 | 37 | | path = path.Trim('/'); |
| 748 | 38 | | string[] split = path.Split('/'); |
| | 39 | |
|
| 2992 | 40 | | for (int i = 0; i < split.Length; i++) |
| | 41 | | { |
| 748 | 42 | | split[i] = Uri.UnescapeDataString(split[i]); |
| | 43 | | } |
| | 44 | |
|
| 748 | 45 | | return string.Join("/", split); |
| | 46 | | } |
| | 47 | | } |
| | 48 | | } |