| | 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 | | { |
| 9108 | 14 | | if (path == null) |
| | 15 | | { |
| 0 | 16 | | return null; |
| | 17 | | } |
| | 18 | |
|
| 9108 | 19 | | path = path.Trim('/'); |
| 9108 | 20 | | string[] split = path.Split('/'); |
| | 21 | |
|
| 39088 | 22 | | for (int i = 0; i < split.Length; i++) |
| | 23 | | { |
| 10436 | 24 | | split[i] = Uri.EscapeDataString(split[i]); |
| | 25 | | } |
| | 26 | |
|
| 9108 | 27 | | return string.Join("/", split); |
| | 28 | | } |
| | 29 | |
|
| | 30 | | public static string UnescapePath(this string path) |
| | 31 | | { |
| 2352 | 32 | | if (path == null) |
| | 33 | | { |
| 0 | 34 | | return null; |
| | 35 | | } |
| | 36 | |
|
| 2352 | 37 | | path = path.Trim('/'); |
| 2352 | 38 | | string[] split = path.Split('/'); |
| | 39 | |
|
| 9896 | 40 | | for (int i = 0; i < split.Length; i++) |
| | 41 | | { |
| 2596 | 42 | | split[i] = Uri.UnescapeDataString(split[i]); |
| | 43 | | } |
| | 44 | |
|
| 2352 | 45 | | return string.Join("/", split); |
| | 46 | | } |
| | 47 | | } |
| | 48 | | } |