2 //------------------------------------------------------------------------------
3 // <copyright file="_UncName.cs" company="Microsoft">
4 // Copyright (c) Microsoft Corporation. All rights reserved.
6 //------------------------------------------------------------------------------
7 using System.Globalization;
11 // The class designed as to keep minimal the working set of Uri class.
12 // The idea is to stay with static helper methods and strings
13 internal class UncNameHelper {
17 internal const int MaximumInternetNameLength = 256;
19 private UncNameHelper() {
26 internal static string ParseCanonicalName(string str, int start, int end, ref bool loopback) {
27 return DomainNameHelper.ParseCanonicalName(str, start, end, ref loopback);
34 // ATTN: This class has been re-designed as to conform to XP+ UNC hostname format
35 // It is now similar to DNS name but can contain Unicode characters as well
36 // This class will be removed and replaced by IDN specification later,
37 // but for now we violate URI RFC cause we never escape Unicode characters on the wire
38 // For the same reason we never unescape UNC host names since we never accept
39 // them in escaped format.
42 // Valid UNC server name chars:
43 // a Unicode Letter (not allowed as the only in a segment)
46 // '.' 46 0x2E (only as a host domain delimiter)
50 // Assumption is the caller will check on the resulting name length
51 // Remarks: MUST NOT be used unless all input indexes are are verified and trusted.
52 internal unsafe static bool IsValid(char* name, ushort start, ref int returnedEnd, bool notImplicitFile) {
53 ushort end = (ushort) returnedEnd;
58 // First segment could consist of only '_' or '-' but it cannot be all digits or empty
60 bool validShortName = false;
64 if (name[i] == '/' || name[i] == '\\' || (notImplicitFile && (name[i] == ':' || name[i] == '?' || name[i] == '#')))
69 else if (name[i] == '.')
74 if (Char.IsLetter(name[i]) || name[i] == '-' || name[i] == '_')
76 validShortName = true;
78 else if (name[i] < '0' || name[i] > '9')
86 // Subsequent segments must start with a letter or a digit
91 if (name[i] == '/' || name[i] == '\\' || (notImplicitFile && (name[i] == ':' || name[i] == '?' || name[i] == '#')))
96 else if (name[i] == '.')
98 if (!validShortName || ((i-1) >= start && name[i-1] == '.'))
101 validShortName = false;
103 else if (name[i] == '-' || name[i] == '_')
108 else if (Char.IsLetter(name[i]) || (name[i] >= '0' && name[i] <= '9'))
111 validShortName = true;
117 // last segment can end with the dot
118 if (((i-1) >= start && name[i-1] == '.'))
119 validShortName = true;
124 // caller must check for (end - start <= MaximumInternetNameLength)
131 #endif // !PLATFORM_UNIX