[NUI] Adjust directory (#903)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / Xaml / XmlnsHelper.cs
1 using System;
2
3 namespace Tizen.NUI.Xaml
4 {
5     internal static class XmlnsHelper
6     {
7         public static string ParseNamespaceFromXmlns(string xmlns)
8         {
9             string typeName;
10             string ns;
11             string asm;
12
13             ParseXmlns(xmlns, out typeName, out ns, out asm);
14             return ns;
15         }
16
17         public static void ParseXmlns(string xmlns, out string typeName, out string ns, out string asm)
18         {
19             typeName = ns = asm = null;
20
21             xmlns = xmlns.Trim();
22
23             if (xmlns.StartsWith("using:", StringComparison.Ordinal)) {
24                 ParseUsing(xmlns, out typeName, out ns, out asm);
25                 return;
26             }
27             ParseClrNamespace(xmlns, out typeName, out ns, out asm);
28         }
29
30         static void ParseClrNamespace(string xmlns, out string typeName, out string ns, out string asm)
31         {
32             typeName = ns = asm = null;
33
34             foreach (var decl in xmlns.Split(';'))
35             {
36                 if (decl.StartsWith("clr-namespace:", StringComparison.Ordinal))
37                 {
38                     ns = decl.Substring(14, decl.Length - 14);
39                     continue;
40                 }
41
42                 if (decl.StartsWith("assembly=", StringComparison.Ordinal))
43                 {
44                     asm = decl.Substring(9, decl.Length - 9);
45                     continue;
46                 }
47
48                 var nsind = decl.LastIndexOf(".", StringComparison.Ordinal);
49                 if (nsind > 0)
50                 {
51                     ns = decl.Substring(0, nsind);
52                     typeName = decl.Substring(nsind + 1, decl.Length - nsind - 1);
53                 }
54                 else
55                     typeName = decl;
56             }
57         }
58
59         static void ParseUsing(string xmlns, out string typeName, out string ns, out string asm)
60         {
61             typeName = ns = asm = null;
62
63             foreach (var decl in xmlns.Split(';')) {
64                 if (decl.StartsWith("using:", StringComparison.Ordinal)) {
65                     ns = decl.Substring(6, decl.Length - 6);
66                     continue;
67                 }
68             }
69         }
70     }
71 }