Follow formatting NUI
[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             {
25                 ParseUsing(xmlns, out typeName, out ns, out asm);
26                 return;
27             }
28             ParseClrNamespace(xmlns, out typeName, out ns, out asm);
29         }
30
31         static void ParseClrNamespace(string xmlns, out string typeName, out string ns, out string asm)
32         {
33             typeName = ns = asm = null;
34
35             foreach (var decl in xmlns.Split(';'))
36             {
37                 if (decl.StartsWith("clr-namespace:", StringComparison.Ordinal))
38                 {
39                     ns = decl.Substring(14, decl.Length - 14);
40                     continue;
41                 }
42
43                 if (decl.StartsWith("assembly=", StringComparison.Ordinal))
44                 {
45                     asm = decl.Substring(9, decl.Length - 9);
46                     continue;
47                 }
48
49                 var nsind = decl.LastIndexOf(".", StringComparison.Ordinal);
50                 if (nsind > 0)
51                 {
52                     ns = decl.Substring(0, nsind);
53                     typeName = decl.Substring(nsind + 1, decl.Length - nsind - 1);
54                 }
55                 else
56                     typeName = decl;
57             }
58         }
59
60         static void ParseUsing(string xmlns, out string typeName, out string ns, out string asm)
61         {
62             typeName = ns = asm = null;
63
64             foreach (var decl in xmlns.Split(';'))
65             {
66                 if (decl.StartsWith("using:", StringComparison.Ordinal))
67                 {
68                     ns = decl.Substring(6, decl.Length - 6);
69                     continue;
70                 }
71             }
72         }
73     }
74 }